程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> Warning: move_uploaded_file() [function.move-uploaded-file]:

Warning: move_uploaded_file() [function.move-uploaded-file]:

編輯:關於PHP編程

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move

今天文件上傳出現Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move

 

<form action="" enctype="multipart/form-data" method="post">
<tr>
  <td width="150" height="30" align="right" valign="middle">請選擇上傳文件</td>
  <td width="250"><input type="file" name="fileup" /></td>
  <td width="100"><input type="submit" name="submit" value="上傳" /></td>
</tr>
</form>
<?php教程
if(!empty($_FILES[fileup][name])){
    $fileinfo=$_FILES[fileup];
        $type=strstr($fileinfo['name'],".");
        if($type!=".jpg"){
          echo "您上傳的文件格式不正確!";
        }else{
          if($fileinfo['size']<209715 && $fileinfo['size']>0){
             $path="10/".$_FILES["fileup"]["name"];
                 move_uploaded_file($fileinfo['tmp_name'],$path);
                 if(is_dir("10/")){
                   $dir=scandir("10/");
                   foreach($dir as $value){
                     echo $value."<br/>";
                   }
                 }else{
                    echo "目錄路徑出錯!";
                 }
          }else{
          echo '文件大小不符合要求!';
          }
        }
}
?>


運行結果:
Warning: move_uploaded_file(10/02.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in E:apps教程erv-win32-2.5.10AppServwww10index_7.php on line 26

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:WINDOWStempphp1A.tmp' to '10/02.jpg' in E:appserv-win32-2.5.10AppServwww10index_7.php on line 26
目錄路徑出錯!


解決辦法,把相對路徑改絕對

$_SERVER[DOCUMENT_ROOT] . '/10/' . $_FILES['fileup']['name'];

解決辦法

move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"])
改為
move_uploaded_file($_FILES["file"]["tmp_name"],"d:/" . $_FILES["file"]["name"])

方法二

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move
上傳的時候出現類似這種報錯,原因是目錄權限是否為可寫的問題。
一般設置777就可以解決。、
修改權限命令:

chmod 777 filename
chmod 777 dirname
sudo chmod 777 filename/dirname
chown wangr:admin dirname -R


注:-R 批量執行

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved