dsxz84851 2016-02-25 21:37 采纳率: 100%
浏览 292
已采纳

move_uploaded_file()返回false

Basically, the method returns false every time and I have tried changing the tmp folder and given PHP writing permissions in the /uploads folder

The PHP script:

<?php
$uploadfile = $_FILES['userfile']['name'];

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], "uploads/$uploadfile")) {
    echo "Uploaded.
";
} else {
    echo "Not uploaded.
";
}
echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>

How I gave permissions: https://gyazo.com/89a706adfefea2a2edf090e7cc11cf66

The form in the html file:

<form method="POST" action="savepic.php" enctype="multipart/form-data">
    <input class="file" type="file" name="userfile">
    <input type="submit" value="Upload">
    <p>Not available...</p>
</form>

The log for errors gave me these two:

PHP Warning: move_uploaded_file(uploads/65 wat.jpg): failed to open stream: Permission denied in C:\inetpub\wwwroot\UPT\test\savepic.php on line 5

PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php8F38.tmp' to 'uploads/65 wat.jpg' in C:\inetpub\wwwroot\UPT\test\savepic.php on line 5

All help much appreciated.

  • 写回答

2条回答 默认 最新

  • dozug64282 2016-02-27 16:28
    关注

    So I finally found out what was the real problem. The folder, which i was trying to upload to, was created by my own user, meaning it wasn't owned by IIS (This article was very helpful in determining that).

    Therefore, I had to change the owner of the folder to IIS_IUSRS and after doing so, the PHP script worked.

    The details on changing owners of folders are perfectly described in the article mentioned before.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统