Forum Moderators: coopster

Message Too Old, No Replies

override php max upload file size

override php max upload file size

         

drooh

1:34 pm on Jun 3, 2009 (gmt 0)

10+ Year Member



Is there a way to over ride php max upload file size?

For instance if your web host does not allow you shell access to modify the php.ini file, is there a way to write a line of code to override this setting?

something like

<?php
upload_max_filesize = 1000mb;
?>

Mahabub

4:08 pm on Jun 3, 2009 (gmt 0)

10+ Year Member



Dear Drooh,

You can use a function ini_set for this purpose. For more details [php.net...]

Thanks
Mahabub

rocknbil

4:21 pm on Jun 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use .htaccess for per-directory control. You will likely also want to alter memory usage, max_upload_time, etc.:

php_flag file_uploads on
php_value post_max_size "20M"
php_value upload_max_filesize "10M"
php_value max_input_time "300"
php_value memory_limit "64M"

The advantage is the above allows you to control uploads on a per-directory basis (the directory where the .htaccess resides) as opposed to an all out system-wide or program-wide alteration.

Previous thread [webmasterworld.com] if you're doing this for image uploads and the probable implications that can arise when you exceed the 2MB limit for images:

GD takes a compressed image, say, .jpg or .gif, and creates a full bitmap in memory to do any manipulation. As soon as you cross the "2MB limitation" of php, this because a resource hog and you have to start increasing the allowed memory for php, or, switch to the less memory intensive IMagick/ImageMagick methods.

drooh

5:04 pm on Jun 3, 2009 (gmt 0)

10+ Year Member



rocknbill

will that work using .htaccess if your web host has the ini set lower and does not allow shell access? will it really override their settings?

rocknbil

7:40 pm on Jun 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, the server I'm deploying this on has stock PHP settings. So it should.

It will take all of five minutes to test. Drop the above into an .htaccess file, upload it and a stock phpinfo() script in the same directory. Request the php info script. See what it says.

Never tested on Windows servers, only Linux based servers.

drooh

7:55 pm on Jun 3, 2009 (gmt 0)

10+ Year Member



wow, yeah it seemed to work. even on win server. thanks!