Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 940585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:58:53+00:00 2026-05-15T21:58:53+00:00

i really really need your help. I’m successfully setting up a connection to my

  • 0

i really really need your help. I’m successfully setting up a connection to my ftp server. However I can’t figure out how I can download a dynamic file from my server. I guess this would help a lot of other people as well cause i couldn’t find a tutorial or explanation anywhere on the web.

I’m simply listing all of my files on my ftp. If i click on one i call download.php which connects again to the server and should download the file to my harddrive. I was able to auto-prompt a download window and a file gets downloaded to my hdd. however only a damaged file where no headers are set.

/* path to files on ftp server … e.g. /folder/folder/name_of_file.jpg */
$p_arr = explode("/", $path);
/* the file name … e.g name_of_file.jpg */
$file = end($p_arr);

//$finfo = finfo_open(FILEINFO_MIME_TYPE); //returns a fatal error - function not found 
//$mimetype = finfo_file($finfo, $file);
//finfo_close($finfo);

//filetype($file)

/* creating a temporyry file to save to */
$tempFile = tempnam("/tmp", "FOO");

if(ftp_get($conn_id, $tempFile, $file, FTP_BINARY)){ 
    /*header Content-type: must be dynamic*/
    //header('Content-type:' . $mimetype);

    /*header to auto_prompt download window*/
    header('Content-Disposition: attachment; filename="'. $file .'"');
    readfile($tempFile);
} else { 
    echo "There was a problem <br>";
    echo $file . "<br>"; //e.g. image.jpg
}

/* deleting the file after the process */
//unlink($tempFile);

1.) i can’t figure out why ftp_get returns false. The connection gets set up and the file exists in the right directory.
2.) i don’t know how i can find out the mimetype of the file on the server and give it the downloaded file, so it’s not damaged.

please help me out here, i’m really stuck. thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:58:54+00:00Added an answer on May 15, 2026 at 9:58 pm

    Try to save it locally first and then push it back to browser.

    Use that code to save your file locally.

    <?php
                    // define some variables
            $folder_path = "YOUR FOLDER PATH";
            $local_file = "LOCAL FILE PATH";
            $server_file = "SERVER FILE PATH";
    
            //-- Connection Settings
            $ftp_server = "IP ADDRESS"; // Address of FTP server.
            $ftp_user_name = "USERNAME"; // Username
            $ftp_user_pass = "PASSWORD"; // Password
            #$destination_file = "FILEPATH";
    
            // set up basic connection
            $conn_id = ftp_connect($ftp_server);
    
            // login with username and password
            $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    
            // try to download $server_file and save to $local_file
            if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
                echo "Successfully written to $local_file\n";
            } else {
                echo "There was a problem\n";
            }
    
            // close the connection
            ftp_close($conn_id);
    ?>
    

    I also found this, maybe it could help you

    My FTP-Server always responded
    “bool(false)” instead of presenting me
    a directory-listing. I had to add
    ftp_pasv($conn_id, true); right after
    the $login_result = ftp_login(…);
    line. After that it just worked fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.