简体   繁体   English

ftp_get将不会下载图像

[英]ftp_get will not download image

    $fp = 'test.png';
    $server_file = "dir/testing.png";

    //-- Connection Settings
    $ftp_server = 'ftp.net';; // Address of FTP server.
    $ftp_user_name ='user'; // Username
    $ftp_user_pass = 'password'; // Password

    // set up basic connection
    $conn_id = ftp_connect($ftp_server,21);

    // login with username and password
   $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);       
   $mode = ftp_pasv($conn_id, TRUE);

   $download=ftp_get($conn_id, $fp, $server_file, FTP_BINARY);
    // try to download $server_file and save to $local_file
    if ( $download) {
        echo "Successfully $fp\n";

    } else {
        echo "There was a problem\n";
    }

    ftp_close($conn_id);

When I run this it says it is successfully, but will not write or download the file. 当我运行它时,它表示已成功,但不会写入或下载文件。 If I echo file_get_contents($fp); 如果我echo file_get_contents($fp); then it will display the image deconstructed into text [in the Web browser] 然后它将显示解构为文本的图像(在Web浏览器中)

In need to download images and video... 需要下载图像和视频...

尝试添加

header('Content-Type: image/png');

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

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