如何设置上传_max_filesize 在. htaccess?

我试着把这两句话

php_value post_max_size 30M
php_value upload_max_filesize 30M

在我的根 .htaccess文件,但这给我带来了“内部服务器错误”的消息。

Php5在服务器上运行

我没有访问 php.ini 的权限,所以我认为 htaccess是我唯一的机会。
你能告诉我哪里出错了吗?

358910 次浏览

php_value upload_max_filesize 30M is correct.

You will have to contact your hosters -- some don't allow you to change values in php.ini

If you are getting 500 - Internal server error that means you don't have permission to set these values by .htaccess. You have to contact your web server providers and ask to set AllowOverride Options for your host or to put these lines in their virtual host configuration file.

If your web server is running php5, I believe you must use php5_value. This resolved the same error I received when using php_value.

What to do to correct this is create a file called php.ini and save it in the same location as your .htaccess file and enter the following code instead:

upload_max_filesize = "250M"
post_max_size = "250M"
php_value memory_limit 30M
php_value post_max_size 100M
php_value upload_max_filesize 30M

Use all 3 in .htaccess after everything at last line. php_value post_max_size must be more than than the remaining two.

Both commands are correct

php_value post_max_size 30M
php_value upload_max_filesize 30M

BUT to use the .htaccess you have to enable rewrite_module in Apache config file. In httpd.conf find this line:

# LoadModule rewrite_module modules/mod_rewrite.so

and remove the #.

I also face internal server error message for inserting php_value upload_max_filesize 5M in my .htaccess file in PHP Laravel Project from c-Panel.

Then I solve it by the following logic -

  1. Create a file named - .user.ini in my Project root Directory
  2. Insert the following code in .user.ini file
upload_max_filesize = 5M
post_max_size = 5M