开发者

Cannot save image with PHP?

开发者 https://www.devze.com 2023-03-04 04:46 出处:网络
I am trying to take a user uploaded file, resize, and fill any empty section with white using this premade code snipit I found here. It seems to be working fine until I attempt to write the code with

I am trying to take a user uploaded file, resize, and fill any empty section with white using this premade code snipit I found here. It seems to be working fine until I attempt to write the code with the below code:

Since this may be a problem with file permissions, the absolute path I am saving to is http://test.local/uploads and the script is running from http://test.local/library/ajaxupload.php.

$save = '../uploads/' . $filename;
$image_p = imagecreatetruecolor($fwidth, $blank_height);
$white = imagecolorallocate($image_p, $colorR, $colorG, $colorB);
ima开发者_如何学运维gefill($image_p, 0, 0, $white);
switch($filetype){
    case "gif":
        $image = @imagecreatefromgif($_FILES[$fileName]['tmp_name']);
    break;
    case "jpg":
        $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']);
    break;
    case "jpeg":
        $image = @imagecreatefromjpeg($_FILES[$fileName]['tmp_name']);
    break;
    case "png":
        $image = @imagecreatefrompng($_FILES[$fileName]['tmp_name']);
    break;
}
@imagecopyresampled($image_p, $image, 0, $top_offset, 0, 0, $fwidth, $fheight, $width_orig, $height_orig);
switch($filetype){
    case "gif":
        if(!@imagegif($image_p, $save)){
            $errorList[]= "PERMISSION DENIED [GIF]";
        }
break;
    case "jpg":
        if(!@imagejpeg($image_p, $save, 100)){
            $errorList[]= "PERMISSION DENIED [JPG]";
        }
    break;
    case "jpeg":
        if(!@imagejpeg($image_p, $save, 100)){
            $errorList[]= "PERMISSION DENIED [JPEG]";
        }
    break;
    case "png":
        if(!@imagepng($image_p, $save, 0)){
            $errorList[]= "PERMISSION DENIED [PNG]";
        }
    break;
}

Edit: OK, following the below instructions I got the error message. It is that the folder doesn't exist or permission is denied.

The folder does indeed exist...

0

精彩评论

暂无评论...
验证码 换一张
取 消