Question

I am uploading user's images with and and then once the full size image upload is complete, I make a compressed copy to use as a thumbnail to be displayed. All works fine except when I try to upload files larger than 13-14MB. For files larger than this, the original full size file gets onto the server but no thumbnail is created.

My code for the upload and compression is:

function compress_image($source_url, $destination_url, $quality) {
    $info = getimagesize($source_url);
    if ($info['mime'] == 'image/jpeg'){$image = imagecreatefromjpeg($source_url);}
    else if ($info['mime'] == 'image/gif'){$image = imagecreatefromgif($source_url);}
    else if ($info['mime'] == 'image/png'){$image = imagecreatefrompng($source_url);}
    imagejpeg($image, $destination_url, $quality);
    return $destination_url;
}


if(isset($_POST['folder'])){
    $filename = $_SERVER['HTTP_X_FILE_NAME'];
    $final_img = $_SESSION['dir']."/".$_SESSION['folder']."/".$filename;

    // UPLOAD FULL IMAGE
    if (file_put_contents($final_img, file_get_contents('php://input'))){

    // CREATE COMPRESSED THUMBNAIL
    if(compress_image($final_img, $_SESSION['dir']."/".$_SESSION['folder']."/thumbs/".$filename, 50)){
        // continue
    }
    else{
        // error
    }

}
else {
    // no post
}

I originally thought it was due to the post or memory limits so i have tried several configurations even up to the following in my php.ini file (and have checked the values using phpinfo() and they are updated) but again no luck.

post_max_size = 1G
upload_max_filesize = 1G
memory_limit = 1G
Was it helpful?

Solution

all sorted, it seems the php.ini file in the root wasn't being used in the subdirectory that this was in. By setting them in the file itself as below it now works:

ini_set('memory_limit','1G');
ini_set('post_max_size','1G');
ini_set('upload_max_filesize','1G');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top