2

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Miger
  • 1,175
  • 1
  • 12
  • 33
  • I suggest checking [max_input_time](https://www.php.net/manual/en/info.configuration.php#ini.max_input_time) and [max_execution_time](https://www.php.net/manual/en/info.configuration.php#ini.max-execution-time). Is there any error? – Ivan Ganchev Dec 10 '19 at 22:58
  • Yea, that's also a thing I considered but I didn't know anything about these two values. Can I increase these values as well? – Miger Dec 11 '19 at 08:58
  • max_input_time is with default setting -1, which means that max_execution_time is used instead. max_execution_time - is with default setting 30 (sec) - change to 300 (or more) and try again. I hope this will help you. – Ivan Ganchev Dec 11 '19 at 20:35

4 Answers4

2

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.

RobIII
  • 8,488
  • 2
  • 43
  • 93
  • I'm not using ImageMagick or anything like that. The image is not there to be manipulated just to be looked at. But I'll look init the `memory_limit` thing, thanks for the hint.. hope it works. – Miger Dec 11 '19 at 08:55
  • 1
    If you're "not using ImageMagick or anything like that" then it doesn't make sense. In that case the file is just a blob of bytes and the only thing that would make a difference is filesize. However, since you said a SMALLER file (filesize wise) with MORE pixels doesn't work over a LARGER file (filesize wise) with LESS pixels I can almost _guarantee_ you there's SOMETHING trying to read/parse/interpret/handle/whatever the image. Maybe a virusscanner? – RobIII Dec 11 '19 at 09:42
  • ok, but how do I know this.. I still can't get this to work. I'll try to do it on my host instead of XAMPP and see if it works there. But it would be really useful if this stuff would work during development as well.. – Miger Dec 12 '19 at 02:50
  • I had a similar problem, and this did work for me. Thanks for saving me a good few hours of headscratching! – Marc Oct 21 '21 at 10:34
0

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

G3ck
  • 204
  • 2
  • 10
  • I've seen this before, changing it to MB doesn't solve the issue. But I didn't know about, the `memory_limit`, I'll look into that, thanks. – Miger Dec 11 '19 at 08:56
  • 1
    Which php version are you using? Please check memory_limit, upload_max_filesize, post_max_size, max_input_time, max_execution_time – G3ck Dec 11 '19 at 09:05
0

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.

Miger
  • 1,175
  • 1
  • 12
  • 33
-1

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.

symcbean
  • 47,736
  • 6
  • 59
  • 94