我有一个网站托管在我无法访问的PC上。我有一个上传表单,允许人们上传最大30MB的mp3文件。我的服务器端脚本是用PHP完成的。
每次我尝试上传文件时,都会收到一个错误,声称文件超过了允许的最大大小,因此我需要增加大小。我在网络上的研究建议更改。htaccess文件,我没有访问权限,所以这将不起作用。其他人建议我添加一个自定义的php.ini文件到我的根目录,但这并不奏效。还有其他建议吗?
我有一个网站托管在我无法访问的PC上。我有一个上传表单,允许人们上传最大30MB的mp3文件。我的服务器端脚本是用PHP完成的。
每次我尝试上传文件时,都会收到一个错误,声称文件超过了允许的最大大小,因此我需要增加大小。我在网络上的研究建议更改。htaccess文件,我没有访问权限,所以这将不起作用。其他人建议我添加一个自定义的php.ini文件到我的根目录,但这并不奏效。还有其他建议吗?
当前回答
现有的答案都有部分解决方案,所以这里是编译的答案:
解决方法一:编辑。htaccess文件 适用于Apache服务器
php_value upload_max_filesize 128M
php_value post_max_size 132M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300
解决方案2:编辑wp-config.php文件 适合Wordpress应用程序
@ini_set( 'upload_max_filesize' , '128M' );
@ini_set( 'post_max_size', '132M');
@ini_set( 'memory_limit', '256M' );
@ini_set( 'max_execution_time', '300' );
@ini_set( 'max_input_time', '300' );
解决方案3:编辑php.ini文件 适用于nginx服务器或php.ini可修改的地方
upload_max_filesize = 128M
post_max_size = 132M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
可选:Nginx服务器 对于nginx增加最大文件上传大小限制(默认1MB),增加client_max_body_size 128M;HTTP或服务器块中的指令。
设置的重要说明:
upload_max_filesize – set this to a value > than your file size post_max_size – set this to a value > than your upload_max_filesize because overall size of the posted fields may be higher than the filesize memory_limit – set this to a value > than your file size because it limits the maximum amount of memory a script may consume max_execution_time – Maximum execution time of each script, in seconds. Set this to 0 (infinite) if your script requires long time to process file max_input_time - Maximum amount of time each script may spend parsing request data. Default is 60 seconds. Set this to -1 if scripts requires more time
最后,不要忘记重新启动服务器。适用于以下内容:
# if php-fpm is used for processing php
sudo service php7.4-fpm restart
# for nginx
sudo service nginx restart
# for apache
sudo service httpd restart
其他回答
有了WAMP,一切都很简单
WAMP图标> PHP > PHP设置> upload_max_filesize = nM > n = (2M, 4M, 8M, 16M, 32M, 64M, 128M, 256M, 512M,或选择(自定义))。
服务自动重新加载。
但是,如果您确实没有访问服务器的权限,您可能想要尝试编写一个分块API。
下面是如何做到这一点的图片。
现有的答案都有部分解决方案,所以这里是编译的答案:
解决方法一:编辑。htaccess文件 适用于Apache服务器
php_value upload_max_filesize 128M
php_value post_max_size 132M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300
解决方案2:编辑wp-config.php文件 适合Wordpress应用程序
@ini_set( 'upload_max_filesize' , '128M' );
@ini_set( 'post_max_size', '132M');
@ini_set( 'memory_limit', '256M' );
@ini_set( 'max_execution_time', '300' );
@ini_set( 'max_input_time', '300' );
解决方案3:编辑php.ini文件 适用于nginx服务器或php.ini可修改的地方
upload_max_filesize = 128M
post_max_size = 132M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
可选:Nginx服务器 对于nginx增加最大文件上传大小限制(默认1MB),增加client_max_body_size 128M;HTTP或服务器块中的指令。
设置的重要说明:
upload_max_filesize – set this to a value > than your file size post_max_size – set this to a value > than your upload_max_filesize because overall size of the posted fields may be higher than the filesize memory_limit – set this to a value > than your file size because it limits the maximum amount of memory a script may consume max_execution_time – Maximum execution time of each script, in seconds. Set this to 0 (infinite) if your script requires long time to process file max_input_time - Maximum amount of time each script may spend parsing request data. Default is 60 seconds. Set this to -1 if scripts requires more time
最后,不要忘记重新启动服务器。适用于以下内容:
# if php-fpm is used for processing php
sudo service php7.4-fpm restart
# for nginx
sudo service nginx restart
# for apache
sudo service httpd restart
我也有这个问题,并通过在/etc/nginx/nginx.conf中设置这个设置来修复它
client_max_body_size 0;
0,即无限。
此外,如果你有一个反向代理运行nginx,服务器也应该有这个设置(这是我在这里抛出的)
你必须找到PHP安装的位置,你会看到PHP .ini文件
只需将该文件打开到任何编辑器中并替换th值
max_file_upload : 2M
也许这应该是对@seanb123和@Fredrick Gauss的评论,但对我来说,在使用PHP 7的Drupal 8.1中,我需要修改的文件位于这里:
/etc/php/7.0/apache2/php.ini
我修改了大约四个其他的php.ini文件,包括一个我的系统称为“加载配置文件”(php -i | grep -i“加载配置文件”)和一个在info.php页面上找到的文件,但它们都没有帮助。找到正确路径的关键是在2012年的一个遗址上发现的。他们说路径“/etc/php5/apache2/php.ini”即使在当时也被弃用了,但它给了我在哪里找到它的线索。PHP7与PHP5略有不同,但概念是相同的。
也许这能帮到像我这样无助的笨蛋。
话虽如此,在我的情况下,OP的答案是,对盒子有管理特权的人必须这么做。
帮助我的网站是:http://www.evilbox.ro/linux/remove-ispconfig-maximum-upload-size-of-2m-for-wordpress/
在PHPMyAdmin中导入文件大小限制
编辑: 我写给自己的信全文如下:
要更改最大上传大小,请编辑upload_max_filesize和 (如果需要?/etc/php/7.0/apache2/php.ini中的post_max_size 旧版本:/etc/php5/apache2/php.ini) /etc/init.d /输入重启
编辑: 由于您正在导入大文件,您可能需要更改处理它们的超时时间。在我的例子中,名为“config.default.php”的文件在/usr/share/phpmyadmin/libraries/config.default.php中找到了变量$cfg['ExecTimeLimit'] = 300; 比如,我把我的价格改成了900美元,因为我进口了一大笔商品。 之后你需要重新启动apache