Michael Munoz
Michael Munoz

Reputation: 19

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); then it will display the image deconstructed into text [in the Web browser]

In need to download images and video...

Upvotes: 2

Views: 1226

Answers (1)

stark
stark

Reputation: 38

Try adding

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

Upvotes: 1

Related Questions