在上传时调整图片大小时出现问题。
// Image Resizer
function MakeThumbnail($inputFile, $filepath, $ext, $maxWidth, $maxHeight) {
if($ext=="jpg" || $ext=="jpeg" ){
$src = imagecreatefromjpeg($inputFile);
}else if($ext=="png"){
$src = imagecreatefrompng($inputFile);
}else {
$src = imagecreatefromgif($inputFile);
}
list($width, $height) = getimagesize($inputFile);
$newwidth = $maxWidth;
$newheight = (strlen($maxHeight)>0) ? $maxHeight : ($height / $width) * $newwidth;
$tmp = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($tmp, $filepath, 100); //<- This is line 300
chmod($filepath, 0777);
imagedestroy($src);
imagedestroy($tmp);
}
<b>Warning</b>: imagejpeg(): Unable to open '/assets/images/reviews/1466108_263109843838629_409857768_n.jpg' for writing: No such file or directory in <b>/MYPATH/includes.php</b> on line <b>300</b><br />
目录已经chmod&#39; d -R到0777
$pic2Path = '/assets/images/reviews/' . $_FILES['TheImage'];
MakeThumbnail($_FILES['TheImage']['tmp_name'], $pic2Path, 'jpg', 800, 600);
答案 0 :(得分:3)
我怀疑您的/assets
目录位于文件系统的根目录下。它可能位于Web服务器的根目录中,因此您可以使用以下内容:
$pic2Path = $_SERVER['DOCUMENT_ROOT'] . '/assets/images/reviews/' . $_FILES['TheImage'];
答案 1 :(得分:0)
您使用了无效路径,
$pic2Path = '../assets/images/reviews/' . $_FILES['TheImage'];
OR
$pic2Path = 'assets/images/reviews/' . $_FILES['TheImage'];