php specific function / url / file max post size?

813 Views Asked by At

I was wondering if you can set the post_max_size only for a specific page or function (in the php.ini)?

You can set it in the .htaccess

php_value upload_max_filesize 4M
php_value post_max_size 4M

but it doesn't work for a specific page. Also the ini_set() doesn't work for a specific page.

Any suggestions?

3

There are 3 best solutions below

1
nikos.svnk On BEST ANSWER

You cannot change the upload_max_filesize at runtime. If you want custom limits for different parts of your app/website you have to set the upload_max_filesize & post_max_size to the maximum value that you want to allow, and after that you have to manually force lower limits with function filesize()

for example: you set upload_max_filesize & post_max_size at 100M, and you can manually reject an upload larger that 50M at a specific page/function by checking the size of the file

0
Ninjakitteh On

There are 3 places you can set it: php.ini for globally on all pages .htaccess and php script for local website/ instance.

try removing your .htaccess and see if it reads from the php.ini. Just remember to also restart your server after changing the php.ini for it to take effect. if using linux, try:

sudo apachectl graceful

If that doesn't work, you will need to check your php code for the max size. if its in the code, its too broad for me to say what it is.

3
NID On

Not possible, unfortunately. post_max_size (and upload_max_filesize) are used before your script is started, so the only way to set them is in .htaccess or php.ini.

upload_max_filesize cannot be changed at runtime (using ini_set).

upload_max_filesize could not be set using ini_set(). The "official" list states that it is PHP_INI_PERDIR