ftp_get不会下载图片

时间:2012-10-16 19:45:47

标签: php ftp

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

当我运行它时它说成功,但不会写或下载文件。 如果我echo file_get_contents($fp);那么它将在[Web浏览器]中将解构的图像显示为文本

需要下载图片和视频......

1 个答案:

答案 0 :(得分:1)

尝试添加

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