I have a feature on my website where one can upload an image for a profile picture. The maximum limit is 250 Kilobytes.
I noticed many people had problems uploading images from fancy cameras (5 and 10 Megapixel cameras), so the raw image (like 5000x5000 pixels) would be 10 Megabytes.
Is there some way to get PHP to shrink the file size down to 250kb or reduce the actual dimensions (5000x5000) until the file is 250kb? How do big sites like Facebook do it and how to you deal with uploading large images?
I just took a look at the file and found out this info:
memory limit = 90M
post_max_size = 8M
upload_max_filesize = 7M
I assume that the largest file anyone is allowed to upload is 7M?
Also, I allow people to upload 5 images at a time. What would be an ideal maximum file size if someone added 5 big pictures at once?
That will probably be enough… not entirely sure. You’ll know it isn’t when you getting an error saying “Fatal error: Allowed memory size of X bytes exhausted”.
Very unlikely your server has a high enough memory limit to shrink such a large file. You can use GD to resize images, http://php.net/manual/en/ref.image.php but again, chances are the memory limit is set too low. If you have access to the php.ini find memory limit and set it to something large. I personally would just make the max file upload 1mb and resize images to the correct ratio.