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

1.4k Views Asked by At

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.

4

There are 4 best solutions below

4
On BEST ANSWER

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.

0
On

There are several places where this can fail:

  • the size of the POST allowed by the webserver (it base 64 encoded hence larger than the file size)
  • the time limit allowed by the webserver for a client to make a request
  • the max upload size allowed by PHP
  • the memory available in PHP to load and process the image (assuming you do anything other than move_uplaoded_file()

Except for the last of these, it has nothing to do with the dimensions of the image.

2
On

I had a similar case in the future. Quite a strange solution, but it worked for me.

Try to specify the size with MB, not M

upload_max_filesize = 256MB
post_max_size = 256MB

It should work. If not, try to increase memory_limit

I hope it helps

0
On

Some Updates:

I've looked into my javascript programming a little and found a few interesting non working implementations.

It seems that this was all a client side problem.. Or at least I think it is. For Some reason my onprogress function doesn't work correctly. I've tried to upload Images with a bigger delay and sometimes this worked out.. other times it didn't though.

I'm not really sure if the client side problem is causing all of this. I'll probably just have to fix the front-end issue and hope the backed issue resolves itself.

Either way I'm going to update this question as soon as I've tried to fix everything.