tags:

views:

357

answers:

3

Using a PHP uploader and was wondering if there was a way to override the default values in php.ini for post_max_size and upload_max_filesize in a specific script?

Don't want to change it universally in php.ini because while it's okay to make the limit big on the uploader in our admin section, we don't want that big of a limit in the public section.

A: 

Changing this value per user is not possible unless you write to an .htaccess file for every visit.

Why don't you simply allow the upload and discard it if it is too big?

I did find this but I don't trust it as HTML has no idea of what you are doing with that input.

EDIT: Basically, as Apache is what handles the actual physical transferring of the file, you need Apache to be aware of any limits before the user submits the form. As HTML has nothing to do with this, you can't set it there and as PHP is only helpful when the file is actually on the server, you need to check it after it has been uploaded. Sorry, I realised my first answer was a bit vague. Hope this helps a bit more.

Christian
+1  A: 

You should be able to do this via a .htaccess file. Say you want to allow 10Mb uploads for the admin area, and 2 for the public side. I'd set the default value (in php.ini) to be 2 Mb, and then in the admin area, add to a htaccess file:

php_flag upload_max_filesize 10M


Edit
This is intended to work on a directory level - I've assumed your admin pages all run from say mydomain.com/admin/ with a physical /admin folder in your webroot (where you put the .htaccess file)

iAn
A: 

Try using the php ini_set function

You should be able to override the default values in the php.ini file this way. Just make sure you call it before any page output.

Jenski
Actually, since the uploaded file is received and parsed before it hits the php code, ini_set won't help you here.
gnarf