doufei9946
doufei9946
2013-06-11 14:05

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

已采纳

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

$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 
";
} else {
       echo "There was a problem while uploading 
";
}

fclose($fp);
ftp_close($conn_id);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanping1920 duanping1920 8年前

    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:

    $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 
    ";
    
    } 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 
    ";
    } else {
    echo "There was a problem while uploading 
    ";
    }
    
    fclose($fp);
    
    ftp_close($conn_id);
    

    Thanks to all for there help.... :-)

    点赞 评论 复制链接分享

相关推荐