0

Can we 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)?

Run
  • 54,938
  • 169
  • 450
  • 748

4 Answers4

3

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.

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194
1

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:

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

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.

someone
  • 1,468
  • 8
  • 9
0

If you can use .htaccess file, put this:

php_value upload_max_filesize 4194288
php_value post_max_size 4194288

4194288 = 4MB

tttony
  • 4,944
  • 4
  • 26
  • 41