PHP文件上传/ move_uploaded_file不工作

时间:2012-01-06 15:08:45

标签: php file file-upload upload

我有以下表格:

<html>
<body>

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

以下脚本:

<?php
error_reporting(E_ALL);

if (($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";


    $moved = move_uploaded_file($_FILES["file"]["tmp_name"], "C:/inetpub/wwwroot/PHP_Ramp/upload/" . $_FILES["file"]["name"]);

    if ($moved) {
        echo "Move: Success";
    }
    else {
        echo "Move Failed";
    }


      echo "Stored in: " . "C:/inetpub/wwwroot/PHP_Ramp/upload/" . $_FILES["file"]["name"];
      }
    }

else
  {
  echo "Invalid file";
  }
?>

出于某种原因,我不断收到“移动失败”。知道为什么文件没有移动?

======== SO认为我需要更多解释一下;所以我在这里打字。 ======

1 个答案:

答案 0 :(得分:6)

检查您是否有权在该文件夹(C:/inetpub/wwwroot/PHP_Ramp/upload/中)写入文件。您可以通过右键单击并选择properties -> Security

来检查文件夹