我用下面的PHP腳本處理的圖片上傳:PHP:圖片不得到保存在指定的路徑
// receive image data
$imgUrl = $_POST['imgUrl'];
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
// set image quality
$jpeg_quality = 100;
// define output name
$output_filename = "uploads/users/croppedImg_".rand();
// make sure only specific types of images get uploaded
$what = getimagesize($imgUrl);
// get extension of image url
$imgUrlParts = explode(".", $imgUrl);
$imgExtension = end($imgUrlParts);
switch(strtolower($imgExtension)) {
case 'png':
$img_r = imagecreatefrompng($imgUrl);
$source_image = imagecreatefrompng($imgUrl);
$type = '.png';
break;
case 'jpeg':
case 'jpg':
$img_r = imagecreatefromjpeg($imgUrl);
$source_image = imagecreatefromjpeg($imgUrl);
$type = '.jpeg';
break;
case 'gif':
$img_r = imagecreatefromgif($imgUrl);
$source_image = imagecreatefromgif($imgUrl);
$type = '.gif';
break;
default: die('image type not supported');
}
$resizedImage = imagecreatetruecolor($imgW, $imgH);
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
$dest_image = imagecreatetruecolor($cropW, $cropH);
imagecopyresampled($dest_image, $resizedImage, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
imagejpeg($dest_image, $output_filename.$type, $jpeg_quality);
$response = array(
"status" => 'success',
"url" => $output_filename.$type
);
print json_encode($response);
我的問題是,畫面從未到達在$ output_filename指定的目錄。有誰知道爲什麼?也許有人知道需要在這裏使用一些額外的代碼。
是否文件夾中? webserver(apache?)是否具有寫入權限? – ggutenberg 2014-09-12 15:09:54