[PHP] Re: help needed with headers

2002-04-27 Thread Yuri Petro

Try this:

header (Content-type: text/plain);
header (Content-disposition: attachment; filename=file.txt);

--
Kind regards,
Yuri.
 www.AceHoster.com  Quality web hosting



Vins [EMAIL PROTECTED]

 I would like to create a text file that doesn't save to disk but askes me
to
 save the file.
 like when i click on a zip file from a website, ie asks me to save the
file
 to somewhere.

 how do i create the file and then tell my browser to ask the user to save
 the file somewhere

 ???





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: help needed with headers

2002-04-27 Thread Donna Robinson

Hi,
I spent ages figuring this one out so it work work on Windoze, Linux, Mac, ...
and this *always* works:

Create a hyperlink for user to click on:
echo ' td class=nbcc
  ahref='.$PHP_SELF.'?action=*download=txtDownload TXT/a/td';

On click, we come back in to this:
if ( $action == '*' ) {
  if ( isset( $download ) ) {
downloadFile( $download );

we have a fn to do the biz:
function downloadFile( $type ) {
  global $PHPSESSID;
  // is it a .txt file or an .rtf file
  if ( $type == 'txt' ) {
// write the stuff to a text file: /downloads/$PHPSESSID.txt
include( '../include/mkcribsheet_txt.inc' );
   // download the file
   if ( file_exists( $txtfile ) ) { 
 $size = filesize( $txtfile ); 
 // this goes all on one line
 header( Content-Type: text/x-c; 
   charset=\iso-8859-1\;
   name=\$txtfile\ );
 header( Content-Length: $size ); 
 header( Content-Transfer-Encoding: base64 ); 
 header( Accept-Ranges: none );
 // You could have filename=$txtfile\  here.  I don't becos the user
 // gets his save as box with $PHPSESSID.txt which is ugly
 header( Content-Disposition: attachment; filename=\cribsheet.txt\ );
 header( Content-Description: PHP Generated Cribsheet ); 
 $fp = fopen( $txtfile, r );
fpassthru( $fp );
 // delete the PHPSESSID.txt file
 unlink( $txtfile );
 // delete the PHPSESSID from the cribsheet so user can go again
 $query = update cribsheet set sess_id='' where sess_id='$PHPSESSID';
 dbCribsheetUpdate( $query );
 }
   exit;
}

good luck

Donna


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php