0

I don't have access to php.ini on my host, and I want to get the maximum file size limit for uploads, via php code. Is there a way to do it?

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
Joao Paulo
  • 1,083
  • 4
  • 17
  • 36
  • Are you wanting just to get info on it, or increase the size because you can't edit the `.ini` file to increase it? If so, [see this answer](http://stackoverflow.com/a/2185500/1415724) to modify via `.htaccess` – Funk Forty Niner Dec 19 '13 at 15:57
  • First i want to get the info. I'm getting a error when i try to upload a big file. After if this is the issue, I'll try to fix it. – Joao Paulo Dec 19 '13 at 16:03
  • Then if you don't have an `.htaccess` file in your root, create one and follow the answer I gave you above, and upload it in ASCII format. That will work. – Funk Forty Niner Dec 19 '13 at 16:05
  • Another thing which may be preventing bigger uploads, could be in your script itself. There are many possibilities. Posting your code could help, if you want me to have a look. – Funk Forty Niner Dec 19 '13 at 16:06

3 Answers3

3

Use ini_get() to get the value of upload_max_size and post_max_size directives::

$upload_max_size = ini_get('upload_max_filesize');
$post_max_size = ini_get('post_max_size');

For just viewing this value along with other information, you could use phpinfo().

UPDATE: If you can somehow manage to update the php.ini configuration, then update it as follows:

; Maximum allowed size for uploaded files.
upload_max_filesize = 2048M

; Must be greater than or equal to upload_max_filesize
post_max_size = 2050M

The above configuration sets the limits as 2 GB. It might not be a good idea to have such huge file upload limits. If you're doing this on a real website, users with malicious intent could use this to upload random files and you'd then run out of disk space. I suggest you set it to something reasonable and display an error message if the file size is larger than that. This could vary per application and might depend on the use-case though.

See also: PHP change the maximum upload file size

Community
  • 1
  • 1
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
  • Thank you. And what is the correct syntax to set this to 2 Giga in php.ini? – Joao Paulo Dec 19 '13 at 16:05
  • 1
    @JoaoPaulo: If you don't have access to edit `php.ini` file, then you can try to set it via `.htaccess`. See [Fred's comment](http://stackoverflow.com/questions/20686087/how-to-get-the-maximum-filesize-allowed-to-upload-in-my-php-settings-with-php/20686115?noredirect=1#comment30978133_20686087) above. – Amal Murali Dec 19 '13 at 16:06
  • I don't have access, but I can ask to admin change. post_max_size = 100000000 ? Is only numbers? In bytes? – Joao Paulo Dec 19 '13 at 16:10
  • See this chart => http://www.t1shopper.com/tools/calculate/ @JoaoPaulo and http://wintelguy.com/gb2gib.html – Funk Forty Niner Dec 19 '13 at 16:12
  • @JoaoPaulo: No, it's in MB. The correct syntax would be: `upload_max_filesize = 2048M` (assuming you're trying to set it to 2GB). See the updated answer. – Amal Murali Dec 19 '13 at 16:25
0

You can use the ini_get() function

giorgio
  • 10,111
  • 2
  • 28
  • 41
0

As explained, ini_get, however you need to check both upload_max_filesize and post_max_size which must be greater.

echo ini_get('upload_max_filesize');
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87