0
我有一個文件上傳腳本:PHP文件上傳move_uploaded_file()以未能打開流
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["picture"]["name"]));
if ((($_FILES["picture"]["type"] == "image/gif") || ($_FILES["picture"]["type"] == "image/jpeg") || ($_FILES["picture"]["type"] == "image/jpg") || ($_FILES["picture"]["type"] == "image/png")) && in_array($extension, $allowedExts)):
if($_FILES["picture"]["error"] > 0):
echo "Error: " . $_Files["picture"]["error"];
else:
move_uploaded_file($_FILES["picture"]["tmp_name"], "/TnA/ProfilePics/" . $_SESSION['ID'] . "." . $extension);
endif;
endif;
但我得到的錯誤:
Warning: move_uploaded_file(TnA/ProfilePics/1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/91/9848191/html/TnA/webservice.php on line 1067
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php5nOdhI' to 'TnA/ProfilePics/1.jpg' in /home/content/91/9848191/html/TnA/webservice.php on line 1067
這裏是我的文件結構:
Web Host Root (I have another site here)
-TnA (Root of this site)
-index.html
-webservice.php
-ProfilePics
-(My target location)
我應該使用什麼相對的目錄url?我試過ProfilePics/1.jpg
和/ProfilePics/1.jpg
都導致相同的錯誤。
編輯:
使用:
move_uploaded_file($_FILES["picture"]["tmp_name"], dirname(__FILE__) . "ProfilePics/" . $_SESSION['ID'] . "." . $extension);
我得到:
Warning: move_uploaded_file(/home/content/91/9848191/html/TnA/ProfilePics/1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/91/9848191/html/TnA/webservice.php on line 1067
如果我使用了完整的HTTP://地址,我得到'警告:move_uploaded_file(HTTP:/ /html/TnA/ProfilePics/1.jpg)[function.move-uploaded-file]:無法打開流:HTTP包裝器不支持/ home/content/91/9848191/html/TnA/webservice.php on line 1067' – SnareChops 2013-03-19 19:43:40
您應該使用**服務器的**內部絕對路徑,而不是您網站的網址。 我用代碼示例編輯了我的答案。 – 2013-03-19 19:47:04
更緊密,但現在我得到這個錯誤(請參閱編輯的問題) – SnareChops 2013-03-19 19:53:34