Can we reduce an image file size with php?
Can we开发者_如何学C reduce an image file size with PHP if it exceed the the limit set by upload_max_filesize
?
For instance, the upload_max_filesize
at my serve is only 3MB, but the image file size for uploading is 4MB, so can I reduce 4MB to 3MB via some PHP function?
Or any other scripting programme can do this (I don't mean using Photoshop to reduce the file size)?
No, you can't. If the file size exceeds upload_max_filesize
, PHP will just refuse the upload, so you have no opportunity to resize it.
No - it's impossible for PHP to ever get hold of that file if it is too big.
You would have to use client-size resizing, which is possible using Flash- or Java-based uploaders:
- Compress images on client side before uploading
- Image resizing client-side with javascript before upload to the server
arnaud is correct. However, if you are able to change the upload_max_filesize, you could increase it and then resize any file that exceeds the max desired size using gd.
If you can use .htaccess
file, put this:
php_value upload_max_filesize 4194288
php_value post_max_size 4194288
4194288 = 4MB
精彩评论