无法将文件上传到Apache 2.2 [英] Can't upload file to Apache 2.2

查看:347
本文介绍了无法将文件上传到Apache 2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache/2.2.15(Win32)PHP/5.3.2

Apache/2.2.15 (Win32) PHP/5.3.2

我正在尝试将文件上传到Apache,并且我的PHP脚本告诉我一切进展顺利(状态代码0),但该文件不在temp目录中.无论文件大小如何,PHP答案总是立即出现. PHP错误日志根本不显示任何错误.

I'm trying to upload a file to Apache and my PHP script tells me everything goes well (status code 0), but the file is not in the temp directory. The PHP answer is always coming immediately, regardless of the file size. The PHP Error log doesn't show any errors at all.

Apache服务器以其自己的用户帐户运行,并且可以完全访问log和doc文件夹.

The Apache server is running on its own user account with full access to the log and doc folders.

PHP.ini

file_uploads = On
upload_tmp_dir =
upload_max_filesize = 10M
upload_tmp_dir="C:\WINDOWS\Temp"

send.html

send.html

<!DOCTYPE html>
<html>
  <body>

  <form enctype="multipart/form-data" action="upload.php" method="post" >
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
  </form>

  </body>
</html>

upload.php

upload.php

<?php
  // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
  // of $_FILES.

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

结果看起来像这样

Array
(
    [userfile] => Array
        (
            [name] => strings.lua
            [type] => application/octet-stream
            [tmp_name] => C:\WINDOWS\Temp\phpC0.tmp
            [error] => 0
            [size] => 9935
        )

)

文件C:\ WINDOWS \ Temp \ phpC0.tmp不存在.

The file C:\WINDOWS\Temp\phpC0.tmp doesn't exists.

我还错过了其他注意事项/配置吗? Apache服务器已经使用PHP运行了5年以上,并且在所有其他方面都可以正常工作.我无法将Apache或PHP升级到新版本,因为这是生产中的应用程序,客户不会冒险进行升级.

Are there any other considerations/configurations that I have missed out? The Apache server has been running with PHP for over 5 years and works fine in all other aspects. I can't upgrade Apache or PHP to a newer version because this is an application in production and the customer won't risk to an upgrade.

推荐答案

临时文件仅存在到PHP脚本upload.php结束为止.这确实是暂时的.

The temporary file only exists until the end of your PHP script upload.php. It's truly temporary.

您应该使用move_uploaded_file立即移动文件:

You should move the file right away using move_uploaded_file:

http://www.php.net/move_uploaded_file

类似的东西:

$savePath = "path/where/you/really/wantit/" . $_FILES['userfile']['name'];

move_uploaded_file($_FILES['userfile']['tmp_name'], $savePath);

通过此链接:

http://us3.php.net/手册/zh/features.file-upload.post-method.php

如果文件尚未移走或重命名,则该文件将在请求结束时从临时目录中删除.

The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

这篇关于无法将文件上传到Apache 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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