Jump to content

[SOLVED] Force download with HTML content


PC Nerd

Recommended Posts

Hi,

I'm trying to get this script to work, so that it still outputs the HTML of the page, and then sends the download.  The overall effect is that once the page (HTML) is dowloaded, the File is sent so that the information on the html page is viewable ( it contains information regarding licences and passwords within the file being downloaded).

* this code does force the download - just doesnt output any of the HTML.  It is called as the last like after all the HTML.  I am using output buffering so my code goes:

ob_start();HTML outputdownload();ob_flush();

 

thanks

 

function download() {      if(is_file(FILE))     {        // required for IE        if(ini_get('zlib.output_compression')) {         ini_set('zlib.output_compression','Off');      }  

      $mime="application/vnd.ms-excel";      header('Pragma: public');   // required        header('Expires: 0');       // no cache        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');        header('Cache-Control: private',false);        header('Content-Type: '.$mime);        header('Content-Disposition: attachment; filename="'.basename(STATIC_NAME).'"');        header('Content-Transfer-Encoding: binary');        header('Content-Length: '.filesize(FILE));    // provide file size        readfile(FILE);       // push it out     }

 

 

*** Un fortunately for some reason the CODE tags didnt work.

Link to comment
https://forums.phpfreaks.com/topic/138794-solved-force-download-with-html-content/
Share on other sites

the best way to do this..

 

is send the user to a landing page(page with passwords etc).. then open a new window @ the download url with javascript or maybe an iframe could work aswell.. THAN the download box will promt.. and that page won't close..

 

because when you output the headers to force download.. then add html to the bottom of it.. you're only corrupting the file you want to send.. so do it the way I mentioned :)

Ok - ended up with the target="_blank" option.... and used a cookie across the current page to that  ( using the link). That way the file was still only downloadable only once even if they refreshed with the same data etc.

 

Thanks!!! :)

Archived

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

×
×
  • Create New...

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.