Http 文件上传 - 超过 25mb 的文件失败 - PHP 上传脚本
我已经为此苦苦挣扎了 20 多个小时,现在我真的很感谢您的帮助!
我在这里简化了问题,所以代码非常简单。基本上这个上传脚本工作得很好,直到我尝试上传大于 25MB 的文件,然后它失败了。 PHP 没有给出任何错误。
index.htm
<form enctype="multipart/form-data" action="upload.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
upload.php
<?php
$target_path = "uploaded/";
$target_path = $target_path.basename( $_FILES['uploadedfile']['name']);
/***/highlight_string(print_r($_FILES, true)); //check array
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name'])." has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
?>
php.ini
[PHP]
post_max_size = 32M
upload_max_filesize = 32M
我的主机通知我服务器上的上传限制为 32MB。运行 phpinfo() & ini 中的变量正在更改。这不是超时问题(下载文件时运行了 16MB 上传 - 它比 25MB 上传时间长了几分钟,但仍然有效)。
我已经将 $_Files 数组作为字符串吐出以进行错误检查,这就是失败时得到的结果:
Array
(
[uploadedfile] => Array
(
[name] => 30.tif
[type] =>
[tmp_name] =>
[error] => 7
[size] => 0
)
)
There was an error uploading the file, please try again!
有什么想法吗?在不同的服务器上尝试过,都出现同样的问题。
I've been banging my head against this for 20+ hours now I would really appreciate some help!
I have simplified the problem here so the code is very simple. Basically this upload script works perfectly until I try to upload a file bigger than 25MB then it fails. PHP gives no errors.
index.htm
<form enctype="multipart/form-data" action="upload.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
upload.php
<?php
$target_path = "uploaded/";
$target_path = $target_path.basename( $_FILES['uploadedfile']['name']);
/***/highlight_string(print_r($_FILES, true)); //check array
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name'])." has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
?>
php.ini
[PHP]
post_max_size = 32M
upload_max_filesize = 32M
My host informed me that the upload limit on the server is 32MB. Ran phpinfo() & the variables in the ini are being changed. It is not a timeout issue (ran a 16mb upload when downloading a file - it took several minutes longer than the 25MB upload but still worked).
I have been spittin out the $_Files array as a string for error checking, heres what I get when it fails:
Array
(
[uploadedfile] => Array
(
[name] => 30.tif
[type] =>
[tmp_name] =>
[error] => 7
[size] => 0
)
)
There was an error uploading the file, please try again!
Any ideas? Tried it on different servers with the same problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 this,它无法将文件写入磁盘。你能检查配额/磁盘空间/等吗?
According to this, it failed to write files to disk. Can you check quota/disk space/etc.?
memory_limit 也可能限制可上传文件的大小。
memory_limit might also restrict the size of uploadable files.
您的错误不是大小,错误代码7是因为文件“无法保存在磁盘中”。
要了解更多错误,请阅读:上传代码错误
尝试更改指令“在 php.ini 文件中添加“upload_tmp_dir”并检查是否允许上传文件:“file_uploads = On”。
Your error don't is for the size, the error code 7 is because the file "can't be save in the disk."
to more errors read: Upload code errors
Try change the directive "upload_tmp_dir" in php.ini file and check if is allow the upload of file: 'file_uploads = On'.
谢谢大家,我现在确信这是一个主机问题,而不是我这边的问题 - 尽管我已经在多个主机上尝试过了 - 我认为 http post 被限制在 25MB 左右是很常见的。
我现在已将上传程序设置为最大文件大小为 20MB,这应该使其在大多数主机上都非常安全。
Thanks everybody, I'm sure now that it is a host problem, not a problem on my end - even though I've tried it on several hosts - I think it's pretty common for http post to be limited to around 25MB.
I have now set my uploader to take a maximum file size of 20MB, that should make it pretty safe on most hosts.