Re: Downloading files

From: Date: Tue, 09 Apr 2002 15:59:07 +0000
Subject: Re: Downloading files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-92250@lists.php.net to get a copy of this message
Try this: <?php // Open the file to send. $sFilePath = "/home/scott/public_html/TEST.doc"; $iFilePointer = fopen( $sFilePath, "r" ); // Get file content. $sContents = fread( $iFilePointer, filesize( $sFilePath ) ); // Close the file. fclose( $iFilePointer ); // Send HTTP headers. header( "Expires: 0" ); header( "Cache-Control: no-cache" ); header( "Content-Type: application/save-as" ); header( "Content-Disposition: attachment; filename=".basename( $sFilePath ).";"); header( "Content-Length: ".filesize( $sFilePath ) ); // Feed file to client. echo $sContents; ?> As you give the client Content-Type: application/save-as - it will not know what mime type the file is, and the browser will give the user a save-as prompt. This works in explorer - I haven't checked it in Mozilla etc - so you might have to tweak it a bit. Cheers Scott ----- Original Message ----- From: "Declan Kenny" <kenny_declan@hotmail.com> To: <php-general@lists.php.net> Sent: Tuesday, April 09, 2002 1:20 PM Subject: [PHP] Downloading files > Hi folks, > > Ok I am trying to make a download area for files (including word files). > How do I force a download of a word document rather than have it opening in > IE? > > Declan > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#92250) next »