Re: Downloading files

From: Date: Wed, 10 Apr 2002 00:54:19 +0000
Subject: Re: Downloading files
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-92321@lists.php.net to get a copy of this message
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" <ScottH@jamwarehouse.com> wrote in message 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" <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 (#92321) next »