Re: serving up blobs for download

From: Date: Sun, 09 Jul 2000 17:53:26 +0000
Subject: Re: serving up blobs for download
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-5618@lists.php.net to get a copy of this message
"Rob Montgomery" <Robert.L.Montgomery@Home.com> wrote... > I want users to be able to download (not view with a viewer) Users are _able_ to do this by right-clicking and selecting Save Target As, or simillar. I suspect you mean that you want to _force_ a download to happen. > pdf files which I have stored as blobs in MySQL, so the php > script reads the blob into a variable, then does this: > > header("content-type: application/octet-stream"); > header("content-disposition: filename=$filename"); > echo $blob; > > With Netscape, this works great, the file save box opens and > the filename to save as defaults to my variable $filename. > > The problem is that IE thinks it should be able to find a > program to "view" the content-type of application/octet-stream. > Netscape defaults to downloading unknown types, IE just gets > confused. That's because you have deliberately confused it by giving it the wrong MIME type for the file. The correct content-type for PDF is application/pdf. > Does anyone know how to handle that problem? Is there some > other content-type which is specifically used for downloading? "How do I 'force' a download" is the most frequently asked question in comp.infosystems.www.authoring.html. If you ask it there you will get lots of bogus advice that will tell you about ways to exploit features of the major browsers to cause the Save As dialog to be displayed most of the time. However the real answer is that you cannot reliably 'force' the browser to do anything. Ultimately, what the browser does with a received file is entirely up to it, you have no control of it whatsoever (heck, you don't even know what the browser is - it could be me, on the end of a telnet connection - what does 'download' mean in that context?). And why would you presume to know what action the user wants? He may want to view the file within the browser or a helper application. If he wants to Save As a file he is quite capable right-clicking and selecting Save Target As.

« previous php.general (#5618) next »