使用 php 上传文件到服务器
Uploading files to server using php
我可以成功上传最大 3-4 MB 的文件。但是当我尝试上传大于 4 MB 的文件时,它开始上传一段时间然后显示 "This webpage is not available" 错误。我在 000webhost 中托管了该站点。但在 localhost 中,我也可以轻松上传更大的文件。请帮我解决这个问题。
您需要在 php.ini 中设置 upload_max_filesize 和 post_max_size 的值:
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
(并重启 Apache)
我相信你有
足够的权限上传文件
并增加了upload_max_filesize
和post_max_size
upload_max_filesize = 40M
post_max_size = 40M
注:
000webhost.com
是一个免费的托管站点,您不能指望速度很快,而且在大多数情况下它会失败。如果您想看到更好的响应,请尝试付费托管或尝试一些免费的应用程序托管商,例如 heroku
根据网友评论更新:
I can do that in localhost. But where can I find the php.ini file as I have already hosted the site
您在在线服务器中找不到 php.ini
。但是您可以使用 .htaccess
文件和其他几种方法来设置它..
新建一个.htaccess
文件,里面有如下代码,就可以实现你的需要了。
php_value upload_max_filesize 40M
php_value post_max_size 40M
我可以成功上传最大 3-4 MB 的文件。但是当我尝试上传大于 4 MB 的文件时,它开始上传一段时间然后显示 "This webpage is not available" 错误。我在 000webhost 中托管了该站点。但在 localhost 中,我也可以轻松上传更大的文件。请帮我解决这个问题。
您需要在 php.ini 中设置 upload_max_filesize 和 post_max_size 的值:
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
(并重启 Apache)
我相信你有
足够的权限上传文件
并增加了
upload_max_filesize
和post_max_size
upload_max_filesize = 40M
post_max_size = 40M
注:
000webhost.com
是一个免费的托管站点,您不能指望速度很快,而且在大多数情况下它会失败。如果您想看到更好的响应,请尝试付费托管或尝试一些免费的应用程序托管商,例如 heroku
根据网友评论更新:
I can do that in localhost. But where can I find the php.ini file as I have already hosted the site
您在在线服务器中找不到 php.ini
。但是您可以使用 .htaccess
文件和其他几种方法来设置它..
新建一个.htaccess
文件,里面有如下代码,就可以实现你的需要了。
php_value upload_max_filesize 40M
php_value post_max_size 40M