Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

force download error

Explorer ,
Mar 29, 2012 Mar 29, 2012

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.

TOPICS
Server side applications
606
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 04, 2012 Apr 04, 2012
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines