phpfile-uploadimage-sizeimage-resolution

PHP cannot upload images bigger than ~ 6500px (the size of the file doesn't matter)


I'm using XAMPP for my project. I'm trying to upload really big images and I've noticed that it doesn't work with all images.

After trying it out a few times I came to the conclusion that images which have a higher resolution than something about 6500px in width do not upload.

I've also found out that the file size doesn't seem to matter since a 1.4MB Image with a resolution more than 6500px won't upload but another with 4.8MB but small in resolution uploads without any problem.

Somehow the reason why the image is not being uploaded is with the resolution and not with the file size.

The only code I've to show for is the upload. However there's nothing special about it. As mentioned, other images upload perfectly fine, only the ones with a too high resolution don't.

php code:

move_uploaded_file($imageUploadFile, $taget_original)

php.ini

post_max_size=10000M
upload_max_filesize=10000M

Is there any solution to this problem? Do I need to specify somewhere that I want to upload high resolution images?

This is really important since I want to be able to upload 8k to 16k images. At the moment this doesn't work even if the file size should be small enough, it won't upload the image for some reason.


Solution

  • I wouldn't be looking in the upload size department but in the (allowed) memory size department (e.g. memory_limit. I bet you're using ImageMagick or something to actually do something with the image.

    Also see here and here. Just make sure you read the documentation because the values are supposed to be specified in bytes, not megabytes (also see the comments on those answers).

    I would try something like:

    $limit = 2 * (1024 * 1024 * 1024); // 2Gb
    
    // set memory limit
    ini_set(‘memory_limit’, $limit);  // For testing purposes you could try -1 (for unlimited) instead of $limit
    // pixel cache max size
    IMagick::setResourceLimit(imagick::RESOURCETYPE_MEMORY, $limit);
    // maximum amount of memory map to allocate for the pixel cache
    IMagick::setResourceLimit(imagick::RESOURCETYPE_MAP, $limit);
    

    What the actual limit is supposed to be I guess will have to be found out by trial-and-error and will also depend on the amount of memory available ofcourse. If you're on shared hosting then this might (or: most likely will) be a problem.