php 上传文件大小限制_如何增加PHP文件上传大小限制

php 上传文件大小限制

php 上传文件大小限制

If you’ve got a web application that uploads files to the server through a PHP script, you might have noticed that by default you can’t upload terribly large files. Here’s how to change it.

如果您有一个Web应用程序通过PHP脚本将文件上传到服务器,则可能已经注意到,默认情况下,您无法上传非常大的文件。 更改方法如下。

The reason the limit is set fairly low by default is for stability and security reasons – a malicious script or attacker could attempt to DoS your server with large file uploads and temporarily shut your application down.

默认情况下将限制设置为较低的原因是出于稳定性和安全性的考虑–恶意脚本或攻击者可能试图通过上传大文件来对服务器进行DoS并暂时关闭应用程序。

To change the values you’ll need to edit your php.ini file, normally found at this file path:

要更改值,您需要编辑您的php.ini文件,该文件通常在以下文件路径中找到:

/etc/php.ini

/etc/php.ini

Here are the settings you want to change:

以下是您要更改的设置:

post_max_size This setting controls the size of an HTTP post, and it needs to be set larger than the upload_max_filesize setting.

post_max_size此设置控制HTTP帖子的大小,并且需要将其设置为大于upload_max_filesize设置。

upload_max_filesize This value sets the maximum size of an upload file.

upload_max_filesize此值设置上传文件的最大大小。

memory_limit You’ll want to make sure your script memory limit is set to a decent size, probably larger than either of the other two settings.

memory_limit您将要确保将脚本内存限制设置为适当的大小,可能大于其他两个设置中的任何一个。

Setting the Variables

设置变量

You can set the values by using a numeric value followed by M for the amount of MB you want to allocate for each variable. For instance, to allow 20MB files to be uploaded, you’d use something like this:

您可以通过使用数值后跟M表示要为每个变量分配的MB数量来设置值。 例如,要允许上传20MB的文件,您可以使用以下方法:

memory_limit = 64M upload_max_filesize = 20M post_max_size = 25M

memory_limit = 64M upload_max_filesize = 20M post_max_size = 25M

You’ll need to restart your Apache server once you’ve made this change, with this command:

进行此更改后,您需要使用以下命令重新启动Apache服务器:

/etc/init.d/httpd restart

/etc/init.d/httpd重新启动

Setting the Upload Size Per Application

设置每个应用程序的上传大小

You can make this setting change for a specific web application by putting it into the .htaccess file instead, in the directory of the application. Note that this will only work if your server has enabled overrides for your virtual host or server.

您可以通过将特定的Web应用程序放入应用程序目录中的.htaccess文件中来更改此设置。 请注意,这仅在服务器为虚拟主机或服务器启用替代功能时才有效。

For instance, you could put the following into the file:

例如,您可以将以下内容放入文件中:

php_value memory_limit = 64M php_value upload_max_filesize = 20M php_value post_max_size = 25M

php_value memory_limit = 64M php_value upload_max_filesize = 20M php_value post_max_size = 25M

Once you save the file, the changes should be applied.

保存文件后,应应用更改。

翻译自: https://www.howtogeek.com/50792/how-to-increase-the-php-file-upload-size-limit/

php 上传文件大小限制

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值