我剛剛完成編碼我的PHP應用程序現在的編碼已經變得有些巨大,並且我正在使用的評論看起來醜陋和無效,因爲每一行代碼我評論過//,這是我的第一個編碼,我是完全不知道採用哪種方法來使我的評論看起來更好,更清晰,以備將來參考給我或任何人。我會很感激,如果有人建議我的例子模式..我應該採用哪種模式來評論我的php代碼?
這裏是我用我醜陋的評論寫的函數。您將使用哪種模式來評論代碼?
//function to check if the uploaded Image is valid
function valid_image($image, $target, $url, $width, $height = 0) {
//Check if the uploaded image is of type jpeg
//if not then pop up a warning message and return false and redirect back
if($image["type"] !== "image/jpeg") {
alert('File must be of type image/jpeg');
redirect_url($url);
return false;
}
//Check the file Dimension of the Uploaded Image if it matches with the defined Value
//Get the Dimensions of the image
list($image_width, $image_height) = getimagesize($image['tmp_name']);
//If the Parameter Height is empty then just check the image width and ignore the height rule
//Print the appropriate message and return false and redirect back
if($height == '0') {
if($image_width !== $width) {
alert("Incorrect File Dimension for " . $image['name'] . " Please make sure it is $width in width");
redirect_url($url);
return false;
}
}
//If the function has got all the parameter then check both the defined height and width
//Print the appropriate message and return false and redirect back
else if($image_width !== $width || $image_height !== $height) {
alert("Incorrect File Dimension for " . $image['name'] . " Please make sure it is $width X $height ");
redirect_url($url);
return false;
}
return true;
}
在此先感謝。
意見式樣NO.1:縮進的代碼可以正確 – Eric 2010-09-03 19:47:05