Forum Moderators: coopster

Message Too Old, No Replies

upload_max_filesize, php.ini, and .htaccess

         

Nutter

12:12 pm on Jun 28, 2006 (gmt 0)

10+ Year Member



I'm trying to fill a box in to tell users how large of a file they can upload. It appears I can pull the number out of PHP.ini using ini_get, assuming that ini_get hasn't been disabled. But it may be changed by the .htaccess or ini_set functions. Is there a way to see what the real number is compared to what it is in the php.ini file?

For example - if php.ini has the max size at 2M and I change it in .htaccess (or ini_set) to 8M but PHP is not set up to allow the change, what will get_ini show? I assume the 2M. What will it show if the change is allowed?

coopster

3:24 pm on Jun 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ini_get() [php.net] will return the current value, which may or may not be the same as the value defined in
php.ini
. I'll use error_reporting() [php.net] to demonstrate:
<pre> 
<?php
print ini_get('error_reporting') . "\n"; // default on this server is 4095
ini_set('error_reporting', E_ALL);
print ini_get('error_reporting') . "\n";
ini_set('error_reporting', E_NOTICE);
print ini_get('error_reporting') . "\n";
?>
</pre>
// Prints:
4095
2047
8

Nutter

5:47 pm on Jun 28, 2006 (gmt 0)

10+ Year Member



So, using the following...
echo ini_get('upload_max_filesize').'<br>';
ini_set('upload_max_filesize', '8M');
echo ini_get('upload_max_filesize');

If it echoes out 2M both times it means that it couldn't be changed, correct?

eelixduppy

6:47 pm on Jun 28, 2006 (gmt 0)



I think you cannot use the short-hand syntax here. You must specify an integer in bytes.

[edit]or not ;)[/edit]

[edited by: eelixduppy at 6:51 pm (utc) on June 28, 2006]

coopster

6:48 pm on Jun 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Correct. That particular directive is of type
PHP_INI_PERDIR
which means it can only be changed in
php.ini
,
.htaccess
or
httpd.conf
.

[php.net...]

coopster

6:51 pm on Jun 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




I think with ini_set you cannot use the short-hand syntax. You must specify an integer in bytes.

Actually you can use shorthand notation [php.net] with upload_max_filesize [php.net].

eelixduppy

6:54 pm on Jun 28, 2006 (gmt 0)



coopster, I understand now. I assumed something incorrectly when I read
You may not use these shorthand notations outside of php.ini, instead use an integer value of bytes.
I should have checked if it was changable with ini_set first. ;)

coopster

6:57 pm on Jun 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I use that link in message #5 more than any other page of the manual ;)