上传的文件大于服务器 POST 设置允许的大小
我正在创建一个网站,用户可以在其中上传他的文档。 服务器设置:
upload_max_filesize 2M
post_max_size 2M
FTP上传无限制。
有没有办法允许用户通过 FORM 上传更大的文件?
I'm creating a site in which user can upload his docs.
Settings on server:
upload_max_filesize 2M
post_max_size 2M
The FTP uploading is unlimited.
Is there a way to allow the user upload larger files via FORM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试通过 ini_set 函数在运行时设置 upload_max_filesize 的 php 值。
但这是行不通的,因为变量没有及时设置,因此它无法真正覆盖 php.ini 指令。
因此,如果您无法访问 apache conf,您可以尝试在 .htaccess 中设置此类内容,
我还建议设置 post_max_size 这会很有帮助。
You could try by ini_set function to set the php values for upload_max_filesize at runtime.
but that won't work because the variable is not setted in time so that it can really ovverride the php.ini directives.
So, if you can't access the apache conf, you can try to set this kind of things in the .htaccess
I'd also suggest to set the post_max_size that could help a lot.
如果您无权编辑 php.ini,您可以使用 .htaccess 文件:
根据 http://www.php.net/manual/en/ini.list.php:
值得注意的是,与往常一样,如果您编辑 php.ini 或 apache httpd.conf,则需要重新启动 apache,然后才能看到 Web 中反映的更改环境。
If you don't have access to edit php.ini, you can use your .htaccess file:
According to http://www.php.net/manual/en/ini.list.php:
It's worth noting that as always, if you edit your php.ini or apache httpd.conf you'll need to restart apache before you see the changes reflected in your web environment.
POST 是 HTTP,表单也是。 HTTP 不是 FTP。
除非您安装某种 FTP UI 插件(或 Java/Flash 应用程序),或者只是将 FTP 公开给用户,否则您将无法规避此问题。
POST is HTTP, and so are forms. HTTP is not FTP.
Unless you install some sort of FTP UI plugin (or Java/Flash app), or simply expose the FTP to the users, you're not going to be able to circumvent this.
不,除了精确编辑这两个 php.ini 设置之外,没有其他方法。
No, there is no other way than editing exactly those two
php.ini
settings.如果您确实需要一种方法并且无法更改 upload_max_filesize,请让您的用户将文件分割成 2M 以下的部分。您可以在服务器上加入他们。
也许您可以向用户显示已上传部分的列表。每当用户上传所有部分时,他单击“所有部分上传”,然后服务器将它们加入。
If you really need a way and cannot change upload_max_filesize, let your users split the file up into parts below 2M. You can join them on the server.
Maybe you could show the users a list of the uploaded parts. Whenever the user uploaded all parts, he clicks "All parts uploaded" and then the server joins them.