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=txt">Download 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