1

我在文件上传方面遇到了一个非常烦人的问题。

用户可以在 html 文件字段中选择文件。当他们提交表单时,该文件将被上传。

在服务器端,我只使用标准的 PHP 代码(move_uploaded_file)。我没有做任何奇怪的事情。

一切都很完美。

我可以在服务器上看到文件,我可以再次下载它,...

但是有时这不起作用。我上传文件,处理它,我没有收到任何错误。

但是该文件在服务器上不存在。

每次我上传该特定文件时,我都没有收到任何错误,但它永远不会被保存。

只有当我重命名它(例如 test.file 到 tst.file)我才能上传它并且它实际上会被保存。

我很少遇到这个问题。重命名总是有效的。但我显然不能要求用户重命名他们的文件......

我无法访问 apache tmp 文件目录,也无法访问日志或设置,因此这使得调试更加困难。我只在这个特定的服务器上遇到这个问题(我不管理它;我什至无权访问它),我在许多没有这个问题的服务器上使用完全相同的代码。

如果有人可以在这里帮助我或为我指明正确的方向,我将不胜感激。

4

4 回答 4

2

尝试添加此调试代码:

echo '<pre>';
print_r($_FILES);
echo '</pre>';

您应该会看到一个错误编号。您可以在http://uk3.php.net/manual/en/features.file-upload.errors.php查找它的含义

可能还值得检查以确保目标文件不存在。

于 2009-02-25T10:23:04.743 回答
2

My first thought was filesize issues. In the php.ini, if the post_max_size or upload_max_filesize are too small, you can end up with similar results - where the file just seems to disappear. You would get an error in the apache logs (which you mention you've no access to).

In those cases, the $_FILES array would simply be empty - as if the file never arrived. Since your responses to Gumbo and James Hall show that php is reporting a proper upload, I'm led to wonder about the processing you mention.

If, during the process, your memory gets maxed or the script runs too long, the script may be dying out before it gets a chance to move it. You'll want to check these:

memory_limit

max_execution_time

max_input_time

Otherwise, without the apache logs, I'd say it might be a good idea to start outputting to a log file of your own throughout your file processing script. Try a file_exists on the tmp file, see what info you can get from the file (permissions, etc).

Unfortunately PHP doesn't get involved until the upload is finished, which means you won't get much info during - only after the fact. You best option might be to talk to the hosting company and get access to the logs - even if for a short time. In my experience, I've rarely had trouble getting ot the logs - or at least getting a tech to check the logs for me while I run tests (in the case where a shared server doesn't split their logs - seems ridiculous, but I've seen it before).

Edit: I realize you can't change those php settings, but you might want to see what they are in order to find out if they're potential problems for your script. For instance, a low memory limit will kill your processor script if it's less than the size of the uploaded file.

于 2009-02-25T11:23:06.707 回答
1

如果上传失败,您不会收到类似 PHP 语法错误等的错误。

但是您可以自己检查文件上传状态并向用户报告错误。

于 2009-02-25T10:21:00.133 回答
1
于 2009-07-21T19:01:19.577 回答