I have a problem, where I get 500 internal server error when I try to upload an image that is too big in dimensions. The application works fine on one server and throws 500 internal error on the other. In both cases the application is on shared hosting but I do have some influence on hosting providers 🙂
So the problem is not the weight (MB) but the dimensions (px). Everything over ~1600px width, throws an error. The problem is that I cannot resize the image in PHP before I get the error. Because the app runs fine on one server and not on the other I presume it is some server restriction similar to one with weight (MB). Giving the user a custom error doesn’t resolve the problem, because most users do not know how to resize the image.
Has anyone seen this kind of problem? Could this be some php.ini setting or something else?
2
Answers
I would say that a webserver doesn’t restrict image uploads by dimensions.
If you are sure that there’s not some PHP function restricting the upload by image size in the code, I would suggest increasing these values in your server’s php.ini file:
upload_max_filesize / memory_limit / post_max_size
@user805528
in order to tackle that issue, you need to grab the image, save to a stream (probably file system or php streams) and then calculate its dimensions using getimagedimensions
https://www.php.net/manual/en/function.getimagesize.php
In case your image doesn’t meet your validation criteria, you need to throw an error to the end user and remove the image.
In any other case you can accept your image any way you would normally.