SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    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

  2. #2
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't force anything.

  3. #3

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lkj
    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.
    http://www.sitepoint.com/forums/showthread.php?t=155279

    Quote Originally Posted by lkj
    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
    http://uk.php.net/manual/en/function.ob-gzhandler.php

  4. #4
    SitePoint Member
    Join Date
    Feb 2004
    Location
    toronto
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    may be i didn't make it clear.

    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

  5. #5
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think it's as easy as that?
    You cannot force anything. All you can do is suggest.

    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.

  6. #6
    SitePoint Guru dagfinn's Avatar
    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">
    Or maybe you could just set the Content-Type header to something the browser would want to download? I'm don't know, I'm just thinking out loud.
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  7. #7
    One website at a time mmj's Avatar
    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

  8. #8

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lkj
    may be i didn't make it clear.

    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.
    This is exactly what the mentioned thread is explaining.

  9. #9
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Russia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dagfinn
    Or maybe you could just set the Content-Type header to something the browser would want to download? I'm don't know, I'm just thinking out loud.
    Try this:
    PHP Code:
    header('Content-Disposition: attachment; filename=somefile.ext');
    header('Content-Type: application/x-force-download; name="somefile.ext"'); 

  10. #10
    SitePoint Zealot Narfotic's Avatar
    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?

  11. #11
    SitePoint Evangelist ghurtado's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •