2012-12-26 41 views
1

我在將move_upload_file()函數引用到另一個頁面時遇到問題。它工作沒有任何錯誤。但問題是選定的文件沒有被傳送到指定的目錄。move_uploaded_file()函數在引用另一個頁面時不起作用

我不知道是什麼問題,並感謝任何形式的幫助或建議。

下面是代碼:

PAGE 1(其中輸入被完成):

<form name='NewsForm' method='post' action='conf_news.php' enctype='multipart/form-data' > 

<input type="file" name="file" id="file" value='' > 
<input type='submit' name='AddNews' value='POST' > 

</form> 

它帶來代碼到另一頁 「conf_news.php」 其中i引用所存儲的文件的部分: PAGE 2:

 $PicMessage = ""; 
    $PicName = addslashes($_FILES["file"]["name"]); 
    $PicType = addslashes($_FILES['file']['type']); 
    $PicSize = addslashes($_FILES['file']['size']); 
    $PicError = addslashes($_FILES["file"]["error"]); 
    $PicTempName = addslashes($_FILES["file"]["tmp_name"]); 

$allowedExt = array('jpeg', 'jpg', 'gif', 'png'); 
$a = explode(".", $PicName); 
$extension = end($a); unset($a); 

if((($PicType == "image/gif") 
|| ($PicType == "image/png") 
|| ($PicType == "image/jpeg") 
|| ($PicType == "image/jpg") 
&& ($PicSize > 100) 
&& in_array($extentions, $allowedExt))){ 

    if($PicError > 0){ 
     $PicMessage = "Error Type: ". $PicError. "<br />"; 
    } 

    else{ 
     echo "Upload: ". $PicName. "<br />"; 
     echo "Type: ". $PicType. "<br />"; 
     echo "Size: ". ($PicSize/1024). " Kb<br />"; 
     echo "Stored in: ". $PicTempName; 


     if(file_exists("../photos/". $PicName)){ 
      $PicMessage = "File Already Exists"; 
     } 

     else{ 
      move_uploaded_file($PicTempName, "../photos/". $PicName); 
      $PicMessage = "Stored in: ". "../photos/". $PicName; 
     } 
     } 

} 

else{ 
$PicMessage = "Invalid File Type"; 
} 

圖片消息顯示該文件被轉移,但ptohos文件夾爲空。我真的無法思考什麼是錯的。

很多感謝所有誰都會花時間對我的幫助。

+0

檢查move_uploaded_file()返回的內容 – 2012-12-26 03:00:14

回答

0

嘗試驗證該文件實際上是與POST請求上傳,因爲它說的手冊此功能:move_uploaded_file() ensures the safety of this operation by allowing only those files uploaded through PHP to be moved.您可以驗證該文件是否被通過PHP上傳的功能is_uploaded_file()。這將告訴你該文件是否能夠與move_uploaded_file()一起使用。

替換爲您else聲明:

else if(is_uploaded_file($PicName)) { 
    move_uploaded_file($PicTempName, "../photos/". $PicName); 
    $PicMessage = "Stored in: ". "../photos/". $PicName; 
} 
+0

我應該在哪裏放置is_uploaded_file()函數? – meks

+0

當然,你應該添加調試語句(如'回聲「is_uploaded_file()返回true這裏!」;'或諸如此類)來測試什麼是你的代碼實際上發生的事情。 – L0j1k

+0

「我應該在哪裏放置is_uploaded_file()函數?」它是一個PHP函數,只是叫它 – Popnoodles

1

Ok.I發現出了問題。

in_array($一些推廣,$ allowedExt))){修改成$擴展。其一個小錯誤,但有足夠的能力來延緩我們的work.Also刪除add_slashes()和嘗試。

+0

真的嗎?讓我試試 – meks

+0

也刪除add_slashes()並嘗試 – Arunu

+0

我的情況沒有任何更改? – meks

相關問題