我想上傳一個文本文件,通過PHP從數據庫中創建。上傳文本文件到谷歌上傳通過PHP FTP PUT
文本文件已創建好,但是當我嘗試通過PHP FTP上傳文件時將其置於失敗。
我的代碼:
$filename = "products_admin.txt";
$handle = fopen($filename, 'w+');
fwrite($handle, $content);
fclose($handle);
echo "Attempting to connect to <i>uploads.google.com</i>...<br />";
$ftp_connect = ftp_connect("uploads.google.com", "21", "5000") or die("failed to connect.");
$login_result = ftp_login($ftp_connect, "{usernamehere}", "{passwordhere}") or die("ERROR: Username or Password incorrect.");
if((!$ftp_connect) || (!$login_result)) {
echo "ERROR: Couldn't connect to <i>uploads.google.com</i>, upload failed.<br /><br />";
echo "<a href=\"javascript:location.reload(true)\">Try Again</a>";
exit;
} else {
echo "Connected to <i>uploads.google.com</i>...<br />";
$upload = ftp_put($ftp_connect, $filename, $filename, FTP_ASCII);
if(!$upload) {
echo "ERROR: Failed to upload ".$filename." to <i>uploads.google.com</i>.<br /><br />";
echo "<a href=\"javascript:location.reload(true)\">Try Again</a>";
} else {
echo "Uploading <i>".$filename."</i> to <i>Froogle</i>...<br />";
echo "Successfully uploaded <i>".$filename."</i> to <i>uploads.google.com</i>.<br /><br />";
echo "Done.";
}
}
ftp_close($ftp_connect);
該錯誤消息我得到的是
警告:ftp_put():端口IP不一樣176.32.230.48。第100行中的/home/sites/mysite.co.uk/public_html/admin/controllers/generate_feed.php錯誤:無法將products_admin.txt上傳到uploads.google.com。
來自[docs](http://php.net/manual/en/function.ftp-pasv.php)註釋部分的註釋:如果選擇ftp_pasv()後仍然有問題,則應刷新在x文件和/或y GB之後通過ftp_close()/ ftp_connect()進行連接._ – CarlosCarucce