dsxz84851
2016-02-25 21:37
浏览 276
已采纳

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.

图片转代码服务由CSDN问答提供 功能建议

基本上,该方法每次都返回false,我尝试更改tmp文件夹并在/中给出PHP写入权限 上传文件夹

PHP脚本:

 &lt;?php 
 $ uploadfile = $ _FILES ['userfile'] ['name  ']; 
 
echo'&lt; pre&gt;'; 
if(move_uploaded_file($ _ FILES ['userfile'] ['tmp_name'],“uploads / $ uploadfile”)){
 echo“Uploaded。
”  ; 
}其他{
 echo“未上传。
”; 
} 
echo'以下是更多调试信息:'; 
print_r($ _ FILES); 
 
print“&lt; / pre&gt;”  ; 
 
?&gt; 
   
 
 

我如何授予权限: https://gyazo.com/89a706adfefea2a2edf090e7cc11cf66

html文件中的表单:

 &lt; form method  =“POST”action =“savepic.php”enctype =“multipart / form-data”&gt; 
&lt; input class =“file”type =“file”name =“userfile”&gt; 
&lt; input type  =“提交”值=“上传”&gt; 
&lt; p&gt;不可用 lable ...&lt; / p&gt; 
&lt; / form&gt; 
   
 
 

错误日志给了我这两个: < blockquote>

PHP警告:move_uploaded_file(uploads / 65 wat.jpg):无法打开流:第5行的C:\ inetpub \ wwwroot \ UPT \ test \ savepic.php中的权限被拒绝 \ n

PHP警告:move_uploaded_file():无法在C:\ inetpub \ wwwroot \ UPT \ test \ savepic中将'C:\ Windows \ Temp \ php8F38.tmp'移动到'uploads / 65 wat.jpg' 第5行的.php

非常感谢所有帮助。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    已采纳该答案
    打赏 评论
  • douyi3760 2016-02-25 21:47

    It seems unusual, but you may not have permissions on 'C:\Windows\Temp'. Or your server may not have permissions. There are two ways to fix this:

    1. Change the 'upload_tmp_dir' setting in your php.ini file to a directory that you or the server do have permissions to

    2. Find the Temp directory and change the permissions on it the same way you did with the uploads directory.

    打赏 评论

相关推荐 更多相似问题