Skip to main content
Known Participant
March 29, 2012
Question

force download error

  • March 29, 2012
  • 1 reply
  • 604 views

I am trying to let a user download a file.  here is my code:

<?PHP

// Define the path to file

$file = 'http://www.media.lonelyplanet.com/lpi/12553/12553-11/469x264.jpg';

if(!file)

{

     // File doesn't exist, output error

     die('file not found');

}

else

{

     header('Content-Description: File Transfer');

        header('Content-Type: application/octet-stream');

        header('Content-Disposition: attachment; filename='.basename($file));

        header('Content-Transfer-Encoding: binary');

        header('Expires: 0');

        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

        header('Pragma: public');

        header('Content-Length: ' . filesize($file));

        ob_clean();

        flush();

        readfile($file);

        exit;

}

?>

why doens't it download properly?  when you attempt to download it, the file is unreadable.

This topic has been closed for replies.

1 reply

April 5, 2012