0

我已经尝试使用 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);
4

1 回答 1

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);

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

于 2013-06-12T08:23:11.373 回答