SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    force download of a generated file

    I am trying to make a script output some data as a file that is asked to download. This is how VB appears to do it (modified for my purpose)

    PHP Code:
      header("Content-disposition: filename=download.txt");
      
    header("Content-Length: ".strlen($download));
      
    header("Content-type: unknown/unknown");
        
    header("Pragma: no-cache");
        
    header("Expires: 0");
      echo 
    $download
    but it does not seem to work. The results seem to depend on browser. Someone using IE4 said that $download just showed up in the browser and using NS6 they were asked to save the file that this php code appears in.

    Nothing is being echoed before the code above.

  2. #2
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that code seems to be working fine, what are you putting in $download before this code?

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    some text, it is basically a simple mysql dump. Does have line returns as well.

    On my browser, it normally works if i save the file to disc (when promoted) but not if i open file from current location. the other user was having the problems reported. weird.

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, if you think about it this file is being created on the fly, so how could you open it at it's location when it doesn't really have one?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you sure that the other user was NOT simply opening the .php file directly? (i.e. opening c:\whatever\download.php)

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, it is on a webserver.

  7. #7
    SitePoint Enthusiast numeropi's Avatar
    Join Date
    Apr 2001
    Location
    somewhere between 3.14 and 3.15
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe you could say the url so we could test it "on-site" ? I copied your code and it did work, I was prompted to save the file to disk. Opening from current location or saving to disc had no effect on the received file.

    You could also try to set the content-type to application/octect-stream and see if this has any effect.
    Last edited by numeropi; Sep 21, 2001 at 07:17.


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
  •