从我用来创建缩略图的脚本中得到以下错误消息
I get the following error message when from a script I'm using to create a thumbnail
警告:imagepng()[function.imagepng]:无法打开"Manga/One Piece/asd/Thumbnail"以进行编写:是/homez.380/mangasma/www/mangaUpload.php中的目录,位于第220行
Warning: imagepng() [function.imagepng]: Unable to open 'Manga/One Piece/asd/Thumbnail' for writing: Is a directory in /homez.380/mangasma/www/mangaUpload.php on line 220
多数民众赞成在导致错误的行
thats the line causing the error
imagepng($dst_img,$dir);这是方法
function createthumb($source,$output,$new_w,$new_h) { $dirpos=strrpos($output,"/"); $dir= substr($output,0,$dirpos); if(!file_exists($dir)) { mkdir($dir); chmod($dir,0775); }else { chmod($dir,0775); } $ext=explode(".",$source); $ext=$ext[count($ext)-1]; $ext=strtolower($ext); if (preg_match("/jpg|jpeg/",$ext)){$src_img=imagecreatefromjpeg($source);} if (preg_match("/png/",$ext)){$src_img=imagecreatefrompng($source);} if (preg_match("/gif/",$ext)){$src_img=imagecreatefromgif($source);} echo $src_img; $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$ext)) { imagepng($dst_img,$dir); } elseif (preg_match("/gif/",$ext)) { imagegif($dst_img,$dir); } elseif (preg_match("/jpg|jpeg/",$ext)) { imagejpeg($dst_img,$dir); } imagedestroy($dst_img); imagedestroy($src_img); return array("w"=>$thumb_w,"h"=>$thumb_h); }推荐答案
$dir不应是文件夹,而应是文件的路径(即:$dir = 'Manga/One Piece/asd/Thumbnail/1.png';)
$dir shouldn't be a folder but a path to a file (ie: $dir = 'Manga/One Piece/asd/Thumbnail/1.png'; )
例如,在imagepng($dst_img,$dir);(以及imagegif和imagejpeg)之前,您可以添加一行:
For example, just before imagepng($dst_img,$dir); (and imagegif and imagejpeg), you can add a line :
$dir .= '/test.png';使用函数时,可以/应该将输出文件名作为参数传递
As you're using a function, you can/should pass the output filename as a parameter
更多推荐
imagepng功能不太起作用
发布评论