2010-12-08 65 views
0

我得到的时候从脚本我使用创建缩略图Imagepng功能不太工作

警告以下错误信息:imagepng()[function.imagepng]:无法打开“漫画/海贼王/ ASD /缩略图”写作:是在/homez.380/mangasma/www/mangaUpload.php目录上线220

这就是行导致错误

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); 
} 
+0

文件夹权限正确,但仍然没有写入的部分。 – dbomb101 2010-12-08 14:51:27

回答

3

$dir不应该是一个文件夹,但一个文件路径(即:$dir = 'Manga/One Piece/asd/Thumbnail/1.png';

例如,之前imagepng($dst_img,$dir);(和imagegifimagejpeg),您可以添加一行:

$dir .= '/test.png'; 

正如你使用的功能,你可以/应该通过输出文件名作为参数