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

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

问题描述

Apache/2.2.15 (Win32) PHP/5.3.2

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

Apache 服务器使用自己的用户帐户运行,对日志和文档文件夹具有完全访问权限.

PHP.ini

file_uploads = On上传_tmp_dir =upload_max_filesize = 10Mupload_tmp_dir="C:\WINDOWS\Temp"

发送.html

<身体><form enctype="multipart/form-data" action="upload.php" method="post" ><input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>发送这个文件:<input name="userfile" type="file"/><input type="submit" value="发送文件"/></表单></html>

上传.php

';打印_r($_FILES);echo '</pre>';?>

结果如下

数组([用户文件] =>大批([名称] =>字符串.lua[类型] =>应用程序/八位字节流[tmp_name] =>C:\WINDOWS\Temp\phpC0.tmp[错误] =>0[尺寸] =>9935))

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

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

解决方案

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

您应该立即使用 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/手册/en/features.file-upload.post-method.php

<块引用>

如果文件没有被移走或重命名,文件将在请求结束时从临时目录中删除.

Apache/2.2.15 (Win32) PHP/5.3.2

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.

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

<!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

<?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>';
?>

The result look like this

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

)

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

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.

解决方案

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

You should move the file right away using move_uploaded_file:

http://www.php.net/move_uploaded_file

Something like:

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

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

From this link:

http://us3.php.net/manual/en/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天全站免登陆