我創建了一個腳本,根據它們的比例調整圖像大小。出於某種原因,它會保持回顯「失敗」,並且不會將調整大小的縮略圖移動到我設置的目錄。這個目錄是一個有效的路徑,所以當用PHP創建一個圖像時,我必須做一些錯誤。PHP上傳問題
$set_width = $params['width'];
$set_height = $params['height'];
if($filetype == "image/pjpeg" || $filetype == "image/jpeg") {
$new_image = imagecreatefromjpeg($filetmp);
} elseif($filetype == "image/x-png" || $filetype == "image/png") {
$new_image = imagecreatefrompng($filetmp);
} elseif($filetype == "image/gif") {
$new_image = imagecreatefromgif($filetmp);
}
list($width, $height) = getimagesize($filetmp);
$ratio = $width/$height;
if($width != $set_width || $height != $set_height) {
if($ratio > 1)
{
$set_height = $set_width/$ratio;
}
else
{
$set_height = $set_width;
$set_width = $set_width * $ratio;
}
$resized = imagecreatetruecolor($set_width, $set_height);
$rename = $folder . '_' . time() . mt_rand(1,99) . '.' . end($fileext);
imagecopyresampled($resized, $new_image, 0, 0, 0, 0, $set_width, $set_height, $width, $height);
imagejpeg($resized, "$dirpath/$rename", 100);
imageDestroy($resized);
imageDestroy($new_image);
if(move_uploaded_file($resized, "$dirpath/$rename")) {
return $rename;
} else {
echo 'failed';
}
} else {
$rename = $folder . '_' . time() . mt_rand(1,99) . '.' . end($fileext);
if(move_uploaded_file($filetmp, "$dirpath/$rename")) {
return $rename;
} else {
echo 'failed 2';
}
}
所以值,添加更多的調試輸出,旁邊這個不提供信息的「失敗」。 – 2011-03-04 02:37:09
我會使用IMagick – Zoidberg 2011-03-04 02:40:35