Can't upload file to Apache 2.2

◇◆丶佛笑我妖孽 提交于 2020-01-06 20:11:32

问题


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:


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.



来源:https://stackoverflow.com/questions/35641719/cant-upload-file-to-apache-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!