图像在上传问题上调整大小 [英] Image resize on Upload Issue
本文介绍了图像在上传问题上调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在上传时调整图片大小时出现问题。
Having an issue getting an image resized on upload.
// 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);
}
错误
Error
<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'd -R到0777
The directory has been chmod'd -R to 0777
$pic2Path = '/assets/images/reviews/' . $_FILES['TheImage'];
MakeThumbnail($_FILES['TheImage']['tmp_name'], $pic2Path, 'jpg', 800, 600);
推荐答案
我怀疑你的 / assets
目录位于文件系统的根目录。它可能位于Web服务器的根目录中,因此您可以使用以下内容:
I doubt that your /assets
directory is located on the root of the file-system. It is probably in the root of the web-server, so you could use something like:
$pic2Path = $_SERVER['DOCUMENT_ROOT'] . '/assets/images/reviews/' . $_FILES['TheImage'];
这篇关于图像在上传问题上调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文