SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot arun_md's Avatar
    Join Date
    Aug 2005
    Location
    chennai
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Download command??

    Hi,
    Any Php command is available to download a file form a server?

    Regards,
    Arun.M.D


  2. #2
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do you mean ?

  3. #3
    SitePoint Zealot arun_md's Avatar
    Join Date
    Aug 2005
    Location
    chennai
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for some websites Download option will be there... i need like that.. which php command will be used to download files from server?

  4. #4
    SitePoint Addict Quaint's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's called forced download and you do it like this:

    PHP Code:
    readfile('yourfile.ext');
    header ("Content-Type: application/octet-stream");
    header ("Content-Length: " ob_get_length() );
    header ("Content-Disposition: attachment; filename=$filename");
    ob_end_flush(); 
    or

    PHP Code:
    ob_start();
    echo (
    'echo some stuff');
    // echo more...
    header ("Content-Type: application/octet-stream");
    header ("Content-Length: " ob_get_length() );
    header ("Content-Disposition: attachment; filename=$filename");
    ob_end_flush(); 
    This will send the content of the output buffer to the user as $filename and will force a download dialogue. To get something into the output buffer you could either start it: ob_start() and then echo stuff.. Or you could use function readfile() (as described above)

    There are better versions of the above, so try searching this forum for "force download"!

    GL!

    Quaint Tech
    - Blog on web development and web technology.


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
  •