2014-02-16 56 views
0

我試圖上傳使用HTML表單和PHP文件,代碼是這樣的:HTML上傳文件的目錄不存在

$targetPictureLocation = "/files/images/team/" . strtolower(str_replace(" ","", $_POST['name'])) . ".png"; 
move_uploaded_file($_FILES['file']['tmp_name'], $targetPictureLocation); 

現在我相信了$targetPictureLocation refrences www.domain.com/targetpath/因爲有削減文件的盈方。這是正確的嗎?如果是這樣,然後目錄確實存在,但是我得到這些錯誤:

Warning: move_uploaded_file(/files/images/team/foobar.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/08/11798508/html/domainname/files/scripts/userManagement.php on line 259 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpwzO4X7' to '/files/images/team/foobar.png' in /home/content/08/11798508/html/domainname/files/scripts/userManagement.php on line 259 

我做錯了什麼?

謝謝你這麼多

+0

嘗試'$ _ SERVER [ 'DOCUMENT_ROOT']「。/domainname/files/images/team /「。 strtolower(str_replace(「」,「」,$ _POST ['name']))。 「.png」;''tartgetPictureLocation''中的'' – Subin

+0

同樣的錯誤,除了原路徑中沒有'domainname'這樣的錯誤 –

+0

http://chat.stackoverflow.com/rooms/47580/html-upload-file -directory - 不 - 不存在 – Subin

回答

1

嘗試:

$targetPictureLocation = $_SERVER['DOCUMENT_ROOT']."/domainname/files/images/team/" . strtolower(str_replace(" ","", $_POST['name'])) . ".png";` 

你只添加這將指向PHP的相對路徑:

/家庭/內容/ 08/11798508/HTML/domainname/files/scripts/files/images/team/

這是錯誤的locati上。 PHP$_SERVER['DOCUMENT_ROOT']將返回腳本的基本目錄URL。由於您要上傳的文件夾位於父文件夾中。您應該使用$_SERVER['DOCUMENT_ROOT']和位置變成:

/家庭/內容/ 08/11798508/HTML /域名/文件/圖片/團隊/