我試圖做的是全自動上傳通過使用PHP FTP一個zip文件,然後解壓縮zip文件也是如此。不過首先要注意的是:我在使用PHP的ftp_put函數上傳zip文件時遇到了問題。這是我的腳本:PHP FTP上傳不工作
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $user, $pass); //<!--same as cPanel account user and pass?
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $user";
exit;
} else {
echo "Connected to $ftp_server, for user $user";
}
// server & file info
$file = 'phpBB3.zip';
$ftp_root = '/public_html/';
$site_root = $_SERVER['DOCUMENT_ROOT'].'/scripts/';
// >>>HERE<<<
// upload the file
// >>>HERE<<<
$upload = ftp_put($conn_id, $ftp_root .$file, $site_root . $file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $file to $ftp_server as $file";
}
// unzip the uploaded file (from FTP?)
$unzip = shell_exec("unzip {$file}"); //<!-- how to do this through FTP uploaded files?
// close the FTP stream
ftp_close($conn_id);
這裏發生的事情是,它(有時)上傳文件的一部分(總是相同的量,像900 KB),有時不上傳任何東西。就好像上傳過程被正在執行的腳本的其餘部分中斷,而上傳尚未完成。雖然我不確定這是否是問題的原因。
雖然,它總是給我這個錯誤:
Warning: ftp_put() [function.ftp-put]: Connecting to port 38694 in /home/quicksit/public_html/createacct.php on line 93
對輸出端口始終是不同的,總是比20.000較大(如30.000-50.000)。
誰能幫我這個?
在先進的感謝, Skyfe。
你有沒有試過在ftp_connect()中指定一個端口? – 2011-03-19 20:38:24
端口號碼變化是正常的 - 傳出連接主要是隨機分配的。 – 2011-03-19 20:51:05