我試圖使用ftp將產品上傳到我的服務器。但是我提示以下錯誤消息: FTP連接失敗試圖連接到.....使用ftp_connect將文件上傳到ftp失敗
下面是PHP腳本:
if (isset($submit)){
//connect to ftp server
$ftp_server="123456shop.bugs3.com";
//ftp user name
$ftp_user_name="u12345";
//ftp username password
$ftp_user_pass="abcde";
$con_id=ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($con_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name....";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name".".....";
}
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"]/1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("../product_images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$filep=$_FILES['file']['tmp_name'];
// upload the file
$upload = ftp_put($conn_id, '/home/u408392962/public_html/product_images/', $filep, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $name to $ftp_server ";
}
/*move_uploaded_file($_FILES["file"]["tmp_name"],
"../product_images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../product_images/" . $_FILES["file"]["name"];*/
$sql = "INSERT INTO product (name,price,description,type,qty,IsSpecial,categoryID,IsNew) VALUES ('$_POST[name]', '$_POST[price]', '$_POST[description]','$_POST[type]','$_POST[qty]','$_POST[IsSpecial]','$_POST[categoryID]','$_POST[IsNew]')";
$recordset2 = mysql_query($sql) or die(mysql_error());
echo "<script language=javascript>alert('SUCCESSFULLY Add!')</script>";
echo "<SCRIPT language='Javascript'>
document.location=\"\list.php\";
</SCRIPT>";
}
}
}
else
{
echo "Invalid file";
}
}
誰能幫助我? 非常感謝!
腳本看起來不錯...檢查您的憑據一次。確保它們是正確的。 – 2013-05-06 10:09:51
$ con_id = ftp_connect($ ftp_server)或die(「無法連接」);檢查與服務器建立的連接。嘗試使用error_reporting(1) – Shin 2013-05-06 10:11:19
嘗試連接到公共ftp服務器,查看您的連接是否正常工作。如果成功,則表示問題來自您的ftp服務器。 – Alarid 2013-05-06 10:13:04