Hello everyone,

I have a download directory outside of my web root directory. I am attempting to download a file inside the download folder using fopen(). The file is an eps file. When calling the file it opens up in the browser and does not download. How can I force it to download? The file I am using to download the files is just a php script without any html code in it. Does it need to have any html code to work? Here is a sample of the code:

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Content-transfer-encoding: binary\n");
header("Content-length: " . filesize($download) . "\n");
$fn=fopen($download , "r");
fpassthru($fn);

Any help is greatly appreciated

    Hi,

    what happens if you replace

    $fn=fopen($download , "r");
    fpassthru($fn);

    by

    @readfile($download);
    

      One more thing.

      How can I make it download the file and close the window of the php script?

        Hi,

        how do you call the script ? Directly via your browser or by clicking on a link (a href) ?

          I am using a HTTP POST form but I can modify it.

            If you use a simple link that already would solve the problem since it is a download. The page with the link would remain open and by clicking the link the download pop up will appear.

              Write a Reply...