SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
-
Mar 10, 2004, 08:00 #1
- Join Date
- Feb 2004
- Location
- toronto
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
force a download rather than display
force a download rather than display
I'd appreciate any help on this topic - i'd like the browser to download the info to a file (save) rather than display on screen. Is there a way to compress the content on server that when sent to browser the browser can automatically detect and uncompress it -for the reduction in size of traffic?
Thank you.
lkj
-
Mar 10, 2004, 08:24 #2
You can't force anything.
-
Mar 10, 2004, 08:47 #3
- Join Date
- Oct 2003
- Location
- €uroLand
- Posts
- 1,340
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by lkj
Originally Posted by lkj
-
Mar 10, 2004, 22:34 #4
- Join Date
- Feb 2004
- Location
- toronto
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by drzoid
what i want to do is to rather than displaying the result of a DB query i'd like to force the browser (NetScape/IE)for the content (text) to be downloaded by presenting the file save/as dialog.
e.g.
result from query:
$res = 'this is a test';
echo ( $res);
so when the server returns this query result to the browser instead of displaying it on the screen i want the browser to present to user the file save/as dialog.
i think it's as easy as that?
Thx.
lkj
-
Mar 11, 2004, 01:59 #5i think it's as easy as that?
How the browser handles the file depends entirely on how the browser is configured. And IE will operate in a different manner to Mozilla or Opera. I suggest you do a google search for the "Content-Disposition" HTTP header.
-
Mar 11, 2004, 03:36 #6
- Join Date
- Jan 2004
- Location
- Oslo, Norway
- Posts
- 894
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How about storing the results in a file on the server and making sure the file is of a type that the browser is likely to decide to download? I tried a download on sourceforge. The download page has this:
HTML Code:<META HTTP-EQUIV="refresh" content="5; URL=http://heanet.dl.sourceforge.net/sourceforge/phptal/GetText-0.6.4.tgz">
Dagfinn Reiersøl
PHP in Action / Blog / Twitter
"Making the impossible possible, the possible easy,
and the easy elegant" -- Moshe Feldenkrais
-
Mar 11, 2004, 03:56 #7
- Join Date
- Feb 2001
- Location
- Melbourne Australia
- Posts
- 6,282
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
The traditional way to do this is to issue the following:
header('Content-Type: application/octet-stream');
This forces browsers to save the response to disk.
However, this is not a very good thing to do in my opinion. The most important important reason is that it is intentionally non-standard in that you are lying to the browser (or misleading the browser) about what type the data is in. Another point against this is that forcing users to save something to disk can be highly annoying and breaks usability - they won't be able to the file in whatever application they have set up in their OS file associations to handle that type of file. Instead, they'll have to first save it to disk, then open it.
On the other hand, people are so used to websites that break the standard and do this (for example, download.com, sourceforce, tucows etc all do it) that they expect "downloads" to automatically want to save to disk, so you may have to remind people that they can right-click on the file to save it.
If you include the correct content-type, which your server should do by default, then your user has a choice - the way the file is opened will correspond to their file associations in their operating system, which they have so carefully set up. If they want to save it, then all browsers will allow them to save it to disk, usually by right-clicking on the link.[mmj] My magic jigsaw
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Bit Depth Blog · Twitter · Contact me
Neon Javascript Framework · Jokes · Android stuff
-
Mar 11, 2004, 07:42 #8
- Join Date
- Oct 2003
- Location
- €uroLand
- Posts
- 1,340
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by lkj
-
Mar 11, 2004, 08:37 #9
- Join Date
- Mar 2004
- Location
- Russia
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dagfinn
PHP Code:header('Content-Disposition: attachment; filename=somefile.ext');
header('Content-Type: application/x-force-download; name="somefile.ext"');
-
Apr 29, 2004, 10:27 #10
- Join Date
- Aug 2003
- Location
- Antwerp, Flanders, BE , EU
- Posts
- 166
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
anyone knows how to use this code for a flash movie?
-
Apr 29, 2004, 10:32 #11
- Join Date
- Sep 2003
- Location
- Wixom, Michigan
- Posts
- 591
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This is a PHP forum, not a Flash / ActionScript one.
Having said that, you probably have to turn your swf file into a .exe for the browser to prompt you with the save dialog.Garcia
Bookmarks