使用ftp_fput进行文件上传在图像的情况下不起作用

时间:2013-06-11 14:05:53

标签: php ftp

我已经尝试使用php中的ftp连接将文件上传到服务器并且它适用于html文件但是在图像的情况下,目录被创建但是没有图像将在此目录中上传....我试过以下代码请帮助纠正它

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
ftp_pasv($conn_id, true);

$my_file = "PATH_TO_FILE";

$fp = fopen($my_file, "r");

if (ftp_fput($conn_id, $my_file , $fp , FTP_BINARY)) {
    echo "Successfully uploaded \n";
} else {
       echo "There was a problem while uploading \n";
}

fclose($fp);
ftp_close($conn_id);

1 个答案:

答案 0 :(得分:1)

我为图像上传犯了一个愚蠢的错误我已经使用了ftp_fput而不是ftp_put ....使用ftp_put它正在为图像上传和文件上传提供良好的代码如下:

$conn_id = ftp_connect("FTP_SERVER");
$login_result = ftp_login($conn_id, "FTP_USERNAME", "FTP_PASSWORD");
ftp_pasv($conn_id, true);

/*Image Upload*/
if (ftp_put($conn_id, "REMOTE_SERVER_PATH", "LOCAL_SERVER_PATH",  FTP_BINARY)) {
echo "Successfully uploaded \n";

} else {
echo "ERROR IN FTP UPLOAD";
}

/* HTML UPLOAD */

$fp = fopen("LOCAL_FILE_PATH", "r");

if (ftp_fput($conn_id, "PATH_WHERE_TO_UPLOAD/FILENAME.html" , $fp , FTP_ASCII)) {
echo "Successfully uploaded \n";
} else {
echo "There was a problem while uploading \n";
}

fclose($fp);

ftp_close($conn_id);

感谢所有人的帮助....: - )