简体   繁体   English

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

[英]File upload using ftp_fput not working in case of image

I have tried file upload to server using ftp connection in php and it works fine for html file but in case of images, directories are created but no image will be upload in this directories....i have tried following code please help by correcting it 我已经尝试使用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);

I have made a silly mistake for image upload i have used ftp_fput instead of ftp_put....using ftp_put it is working fine code for image upload and file upload are given below: 我对图片上传犯了一个愚蠢的错误,我使用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);

Thanks to all for there help.... :-) 感谢所有人的帮助.... :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM