SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing binary/text to download function, in PHP?

    Can I grab a text or binary file from a PHP file and pass it on to the browser as to be downloaded so that the browser pops up and asks where you want it to be saved? If so how?

    Thanks.

  2. #2
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All you need is to echo the folowing:

    header("location: yourfile.zip");

  3. #3
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two problems:

    1) It must be done before you send anything else (i dont want to here about the buffer thingy you can turn on and all that, i am just saying that all in all this is bad)

    2) All that does is forward to a page. So if its a php page it will just be displayed, instead of having the browser pop up to have it download.

    Any other suggestoins?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make a file named whatever(I named mine dl.php) and stick this in it.

    PHP Code:
    <?
        header
    ("204 No Content");
        
    header("Content-Disposition: attachment; filename=\"".$file."\"");
        
    readfile($file);    
    ?>
    Then link to files like this.

    <a href="dl.php?file=filename.gif">download file</a>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, this sounds like it is going to work perfectly. Thanks!


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
  •