dongzhuang6247 2016-02-26 01:25
浏览 45
已采纳

无法将文件上传到Apache 2.2

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.

  • 写回答

1条回答 默认 最新

  • dongyirong3564 2016-02-26 01:45
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab