2014-02-25 180 views
0

上失敗我有一個工作代碼,上傳圖片,它工作正常,我的臨時服務器,但部署到住的時候,給出了「無法通過FTP傳輸」,請檢查代碼FTP不同的服務器

if (move_uploaded_file($_FILES['tempImage']['tmp_name'], $upload_to_temp)) { 
      $ftp_path = "employeeimages/" . $filename; 
      $ftphost = FTPDOMAIN; 
      $ftpusr = FTPUSER; 
      $ftppwd = FTPPASSWORD; 
      if (file_exists($upload_to_temp)) { 
       $conn_id = ftp_connect($ftphost) or die("Couldn't connect to $ftphost"); 
       $login_result = ftp_login($conn_id, $ftpusr, $ftppwd); 
       if (ftp_put($conn_id, $ftp_path, $upload_to_temp, FTP_BINARY)) { 
        unlink($upload_to_temp); 
        $image_up = $ftp_path; 

        mysql_query("UPDATE employees SET image = '".$ftp_path."' WHERE id = '".$newid."'"); 
       //  $_SESSION['emp_image'] = $ftp_path; 
       }else{ 
        echo "Error transferring file via ftp!<br/>"; 
        echo $filename . "<br/>"; 
        echo $upload_to_temp . "<br/>"; 
        echo $ftp_path . "<br/>"; 
       } 
      }else{ 
       echo "File does not exist in img/temp!"; 
      } 
     }else{ 
      echo "Error moving file to temp location!<br>"; 

     } 

你能猜出來嗎?

感謝

+2

我甚至在代碼中看不到字符串「無法通過FTP傳輸」。這是從哪裏來的? – Mike

+0

對不起,這是錯誤通過ftp傳輸文件 –

+0

'var_dump($ login_result);'display? – Mike

回答

0

ftp_*()功能失敗,通常會產生警告消息,我必須假設你已經設置error_reporting不顯示它們。我建議至少暫時包裹你的if/else塊象下面這樣就可以診斷錯誤:

$prev = error_reporting(E_ALL); // turn on all error reporting levels 
if(ftp_put(...)) { 

} else { 

} 
error_reporting($prev); // revert to previous error reporting level 

另外,PHP可以在Apache或系統日誌中記錄這些錯誤,或者你不妨implment自己錯誤報告功能使用set_error_handler()來捕獲此信息。