简体   繁体   English

如何获得允许在我的PHP设置中使用php上传的最大文件大小?

[英]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. 我无法在主机上访问php.ini ,我想通过php代码获取上传文件的最大文件大小限制。 Is there a way to do it? 有办法吗?

Use ini_get() to get the value of upload_max_size and post_max_size directives:: 使用ini_get()来获取upload_max_sizepost_max_size指令的值::

$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() . 要仅查看此值以及其他信息,可以使用phpinfo()

UPDATE: If you can somehow manage to update the php.ini configuration, then update it as follows: 更新:如果您可以通过某种方式设法更新php.ini配置,请按照以下步骤进行更新:

; 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. 上面的配置将限制设置为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 另请参阅: PHP更改最大上传文件大小

您可以使用ini_get()函数

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

echo ini_get('upload_max_filesize');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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