简体   繁体   中英

How to get the maximum filesize allowed to upload in my php settings with php?

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?

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

您可以使用ini_get()函数

如上所述, ini_get ,但是您需要同时检查必须更大的upload_max_filesizepost_max_size

echo ini_get('upload_max_filesize');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM