在 PHP 中上传一个非常大的文件时没有错误? [英] No error when uploading a really big file in PHP?

查看:28
本文介绍了在 PHP 中上传一个非常大的文件时没有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于上传文件的 PHP 表单,它工作正常并在出现问题时显示错误消息.这一切都很好.

I have a PHP form for uploading files and it works fine and displays an error message if something went wrong. This is all good.

问题是当我用一个非常大的文件进行测试时,它只是刷新页面,就好像我根本没有发送文件一样,表单中的 $_POST 变量甚至都没有发送到服务器.

The problem is when I test with a really big file, it just refreshes the page as if I hadn't sent a file at all, and none of the $_POST variables from the form are even sent to the server.

我想向用户显示错误,让他们知道文件太大.但是,我不能这样做.

I want to display an error to the user, letting them know that the file is too big. However, I can't do this.

有人知道发生了什么吗?

Does anyone know what is happening?

推荐答案

检查您的 PHP ini 文件,该文件控制 PHP 允许上传的文件大小.这些变量很重要:

Check your PHP ini file, which governs how large a file PHP will allow to be uploaded. These variables are important:

  • 最大上传文件大小 (upload_max_filesize)
  • 最大帖子数据大小 (post_max_size)
  • 内存限制(memory_limit)

任何超出这些范围的上传都将被忽略或出错,具体取决于您的设置.

Any uploads outside these bounds will be ignored or errored-out, depending on your settings.

文档中的这一部分有最好的总结:http://ca3.php.net/manual/en/features.file-upload.common-pitfalls.php

This section in the docs has the best summary: http://ca3.php.net/manual/en/features.file-upload.common-pitfalls.php

另请注意,大多数浏览器不会发送大小超过 2GB 的上传.此链接已过时,但提供了一个想法:http://www.motobit.com/help/scptutl/pa98.htm.有人有更好的信息来源吗?

Also note that most browsers won't send uploads over 2GB in size. This link is outdated, but gives an idea: http://www.motobit.com/help/scptutl/pa98.htm. Anyone have a better source of info on this?

服务器也有一些限制,例如 Apache:http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody

There are also limits that can be imposed by the server, such as Apache: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody

要真正了解发生了什么,您可能应该检查您的网络服务器日志,检查浏览器上传限制(如果您使用的是 firefox),并尝试查看 print_r($_FILES) 是否生成任何有用的错误编号.如果所有其他方法都失败了,请尝试使用 firebug 中的网络流量监视器.关键是确定请求是否甚至发送到服务器,以及它是否是请求(包括标头)的样子.一旦您在链中走得那么远,您就可以返回并查看 PHP 是如何处理上传的.

To truly see what's going on, you should probably check your webserver logs, check the browser upload limit (if you're using firefox), and try seeing if print_r($_FILES) generates any useful error numbers. If all else fails, try the net traffic monitor in firebug. The key is to determine if the request is even going to the server, and if it is what the request (including headers) looks like. Once you've gotten that far in the chain, then you can go back and see how PHP is handling the upload.

这篇关于在 PHP 中上传一个非常大的文件时没有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆