2012-06-15 38 views
1

我使用文件上傳表單將文件上傳到我的服務器。然後我echo $_FILES["file"]["tmp_name"]但它返回給我一個似乎不存在的位置。例如/ tmp/phpBparj4是輸出,但我的/ tmp文件夾中沒有這樣的文件/文件夾。我也檢查了文件夾的適當權限

我的實際擔心是move_uploaded_file($_FILES["file"]["tmp_name"],$target);這不會將上傳的文件移動到目標位置。我也試過move_uploaded_file($_FILES["file"]["tmp_name"].$file_name,$target);

+0

你檢查,而腳本正在運行或之後? – Musa

+0

我檢查後,腳本運行結束 –

+1

它的臨時文件,所以它要腳本後刪除執行完畢 – Musa

回答

2

我不知道我是否理解正確,但爲什麼不能指定文件夾的位置?即」

//set the right path from the server perspective 
$article_file_path = $_SERVER['DOCUMENT_ROOT']; 

// you should check for the file if it is/ or not already there (something like this) 
if (!file_exists($article_file_path ."/your_folder/file_subfolder/". $_FILES["my_file"]["name"])) 
     { do something..... 


// then make your script upload the file exactly where you want it 
move_uploaded_file($_FILES["my_file"]["tmp_name"],   
     $article_file_path ."/your_folder/file_subfolder/".$_FILES["my_file"]["name"]); 

// and the download link to the uploaded file would be something like this: 
echo "http://". $_SERVER["HTTP_HOST"] . "/files-article/".$_FILES["my_file"]["name"]"; 
相關問題