设为首页 收藏本站
查看: 518|回复: 0

[经验分享] PHP的上传文件大小限制增加

[复制链接]

尚未签到

发表于 2017-3-28 10:48:51 | 显示全部楼层 |阅读模式
源文地址:http://translate.google.com.hk/translate?hl=zh-CN&langpair=en%7Czh-CN&u=http://www.cyberciti.biz/faq/linux-unix-apache-increase-php-upload-limit/

by Vivek Gite · 2 comments由维韦克乡间渡假别墅 · 2条评论

H ow do I increase upload file limit from 2MB to 10MB under Apache 2 UNIX / Linux web server? Ĥ我的OW增加限制由2MB的文件上传到10MB下的Apache 2的UNIX / Linux的Web服务器?

Your php installation putting limits on upload file size.把你的PHP安装限制上传文件大小。 The default will restrict you to a max 2 MB upload file size.默认会限制你到最大2 MB的上传文件大小。 You need to set the following two configuration options:您需要设置以下两个配置选项:

upload_max_filesize - The maximum size of an uploaded file. 中upload_max_filesize -上传的文件的最大规模的一个。
memory_limit - This sets the maximum amount of memory in bytes that a script is allowed to allocate. memory_limit的 -这在字节设置的最大内存量,一个脚本所能够申请到。 This helps prevent poorly written scripts for eating up all available memory on a server.这有助于防止写得不好的吃了服务器上所有可用内存的脚本。 Note that to have no memory limit, set this directive to -1.请注意,有没有内存限制,设置这个指令为-1。
post_max_size - Sets max size of post data allowed. post_max_size要 -设置后的数据允许的最大大小。 This setting also affects file upload.此设定也会影响文件上传。 To upload large files, this value must be larger than upload_max_filesize.要上传大文件,该值必须大于upload_max_filesize。 If memory limit is enabled by your configure script, memory_limit also affects file uploading.如果你的内存限制是由配置脚本启用,memory_limit也会影响文件上传。 Generally speaking, memory_limit should be larger than post_max_size.通常说,memory_limit应该比post_max_size要大。
There are two methods two fix this problem.有两种方法2解决此问题。

Method # 1: Edit php.ini方法#1:编辑的php.ini
Edit your php.ini file (usually stored in /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini):编辑你的php.ini文件(通常在/ etc / php.ini文件或/ etc / php.d /的cgi / php.ini文件或/ usr /本地/ etc / php.ini文件中):

# vi /etc/php.ini

Sample outputs:示例输出:

memory_limit =  32M 记录memory_limit = 32M的
upload_max_filesize =  10M 中upload_max_filesize = 10M的
post_max_size =  20M post_max_size的值 = 20米
Save and close the file.保存并关闭该文件。 Restart apache or lighttpd web server:重新启动Apache或lighttpd Web服务器:

# service httpd restart

OR或

# service lighttpd restart


Method #2: Edit .htaccess方法2:编辑。htaccess的
Edit .htaccess file in your root directory.编辑。htaccess的文件在您的根目录。 This is useful when you do not have access to php.ini file.这是非常有用当你无法访问的php.ini文件。 In this example, /home/httpd/html is considered as root directory (you can also create .htaccess file locally and than upload it using ftp / sftp / scp client):在这个例子中,/家/的httpd / html是作为根目录(也可以考虑创建的。htaccess文件上传它比在本地使用FTP / SFTP发布/ SCP的客户端):

# vi /home/httpd/html/.htaccess

Append / modify setting as follows:添加/修改设置如下:

php_value upload_max_filesize 10M php_value中upload_max_filesize 10M的
php_value post_max_size 20M php_value post_max_size要20米
php_value memory_limit 32M php_value memory_limit的32M的
Save and close the file.保存并关闭该文件。

A Note About Suhosin (Optional)关于Suhosin的说明(可选)
This is not installed by default on many servers (latest version of Debian, Ubuntu, and FreeBSD does install Suhosin by default).这不是安装在多台服务器(最新的Debian,Ubuntu的版本默认情况下,和FreeBSD默认没有安装Suhosin的)。 Use phpinfo() to find out if suhosin enabled or not (create test.php):使用phpinfo()函数,看看Suhosin的启用与否(创建test.php):

<?php <?PHP的
   phpinfo ( ) ; 的phpinfo ();
?> ?>
If you are using Suhosin which was designed to protect your servers against a number of well known problems in PHP applications and on the other hand against potential unknown vulnerabilities within these applications or the PHP core itself.如果您使用Suhosin的,目的就是要防止潜在的未知漏洞对您的服务器的一个众所周知的问题,PHP应用程序和数量,另一方面在这些应用程序或PHP的核心本身。 You need to edit /etc/php.d/suhosin.ini to set correct memory and upload limit.您需要编辑的/ etc / php.d / suhosin.ini设置正确的内存和上传限制。 As long scripts are not running within safe_mode they are free to change the memory_limit to whatever value they want.只要不属于safe_mode设置脚本运行,他们可以自由地改变memory_limit的任何值,以他们想要的。

suhosin.memory_limit=32M

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-356323-1-1.html 上篇帖子: 学习PHP那点事… 下篇帖子: PHP的上传文件大小限制增加
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表