php上傳檔案提示找不到路徑

來源:互聯網
上載者:User
本人菜鳥剛學php 想寫一個上傳圖片的程式

$myPicture=$_FILES['myPicture'];
print_r($myPicture);
$error=$myPicture['error'];
echo "error:
";
switch($error){
case 0://這裡需要把臨時檔案移動到指定位置
$myPictureName=$myPicture['name'];
var_dump($myPictureName);
echo "
";
$tmp_name=$myPicture['tmp_name'];
$destination="uploads/".$myPictureName;
echo $destination;
move_uploaded_file($tmp_name,$destination);
echo "檔案上傳成功";
break;
case 1:
echo "1號錯誤";
break;
case 2:
echo "2號錯誤";
break;
case 3:
echo "3號錯誤";
break;
case 4:
echo "4號錯誤";
break;
default:
echo "失敗";

下面是錯誤提示:
Warning: move_uploaded_file(uploads/xx.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Apache\test\register1.php on line 31

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\php25F.tmp' to 'uploads/xx.jpg' in D:\Apache\test\register1.php on line 31


回複討論(解決方案)

move_uploaded_file() 的兩個參數出錯
$destination寫成絕對路徑試試

$destination="uploads/".$myPictureName;
改?
$destination=dirname(__FILE__)."/uploads/".$myPictureName;

??

D:\Apache\test\'uploads 目錄不存在

謝謝各位大大 還是因為沒建立路徑 不過一樓和二樓的我也試了 都行 謝謝

???怎麼回事 我結貼給分 怎麼沒給成啊

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.