Jump to content

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!!! :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.