Jump to content

Archived

This topic is now archived and is closed to further replies.

glenelkins

Download file

Recommended Posts

[code]
function downloadFile($thefile) {
    header ("Pragma: public");
    header ("Expires: 0");
    header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header ("Cache-Control: public");
    header ("Content-Description: File Transfer");
    header ("Content-Length: ".filesize($thefile));
    header ("Content-Disposition: attachment; filename=".$thefile);
    header ("Content-Transfer-Encoding: binary");
    
    $fopen = fopen($thefile);
    fpassthru($fopen);
    fclose ($fopen);
}
[/code]

Ok why when the file download box comes up with the correct file path passed to the function, does it download the file but it wont open images etc, and text documents come up with a load of rubbish or they display some of the code from the download page.

Share this post


Link to post
Share on other sites
<?php
  header('Content-type: application/octet-stream');
  readfile($filename);
  exit;
?>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.