Connecting Tech Pros Worldwide Help | Site Map

Bailing after outputting file

Member
 
Join Date: Feb 2008
Posts: 123
#1: Oct 14 '09
Hi all,

I have a PHP script that is split into 2 parts; first, the user input is analyzed and a txt file is made; second, the remainder of the script generates some HTML output that is displayed.

It looks like the HEADER stuff for the txt file causes the script to stop after the file is produced, and the remainder of the script isn't run. Is there any work around?

Expand|Select|Wrap|Line Numbers
  1.    $filename = "output";
  2.    $ext = "txt";   // file extension
  3.    $mime_type = (PMA_USR_BROWSER_AGENT == 'IE' || PMA_USR_BROWSER_AGENT == 'OPERA')
  4.    ? 'application/octetstream'
  5.    : 'application/octet-stream';
  6.    header('Content-Type: ' . $mime_type);
  7.    if (PMA_USR_BROWSER_AGENT == 'IE')
  8.    {
  9.       header('Content-Disposition: inline; filename="' . $filename . '.' . $ext . '"');
  10.       header("Content-Transfer-Encoding: binary");
  11.       header('Expires: 0');
  12.       header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  13.       header('Pragma: public');
  14.    } else {
  15.       header('Content-Disposition: attachment; filename="' . $filename . '.' . $ext . '"');
  16.       header("Content-Transfer-Encoding: binary");
  17.       header('Expires: 0');
  18.       header('Pragma: no-cache');
  19.    }
  20.  
Thanks!
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#2: Oct 14 '09

re: Bailing after outputting file


You can't give the user two things at once. First create and save the txt file, output the HTML, giving them the a link or auto forward to the txt file that was created.

You can have PHP change the headers so when you auto forward, the browser does not display the content, but instead gives the user an Open/Save/Cancel prompt.


Cheers,



Dan
Reply