PHP 文件上传 / move_uploaded_file 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8759888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:26:58  来源:igfitidea点击:

PHP File Upload / move_uploaded_file Not Working

phpfilefile-uploadupload

提问by SB2055

I have the following form:

我有以下表格:

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

And the following script:

以及以下脚本:

<?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";
  }
?>

For some reason I keep getting "Move Failed". Any idea why the file isn't moving?

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

======== SO thinks I need to explain this more; so I'm typing a sentence down here. ========

======== 所以我认为我需要更多地解释这一点;所以我在这里打一个句子。========

回答by Shyju

Check whether you have permissions in that folder (C:/inetpub/wwwroot/PHP_Ramp/upload/) to write file. You can check the folder by right clicking and selecting properties -> Security

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