Using this method,.. works OK if you choose to save the file, however if you choose to open the file you get a weird behaviour where IE says it can't find the file and a subsequent prompt to create a new one. Does anyone know why it does this and how to overcome it ?
At this stage I've resorted to using some simple javascript to prevent a user clicking on a file and advising them to use right-click save-as until I come up with a more reliable method. "Scott Houseman" <[EMAIL PROTECTED]> wrote in message 003e01c1dfdf$7b3a6490$0b01a8c0@scotth">news:003e01c1dfdf$7b3a6490$0b01a8c0@scotth... > 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" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > 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 > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php