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
  • 51,293
  • 159
  • 419
  • 719

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
  • 95,062
  • 22
  • 198
  • 192
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
  • 431,103
  • 135
  • 960
  • 1,075
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,121
  • 4
  • 24
  • 37