SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Talking Download exe using header()

    Hi,

    can you please tel me how to use this
    header(content type: Application/Force Download) to do a downlod. asume the exe file name is abc.exe

    Thanks.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=abc.exe");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . @filesize('abc.exe')); 

    set_time_limit(0); 
    @
    readfile('abc.exe'); 
    Some browsers don't like 'force download'. I'd use x-download or octet-stream.

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hai Dan,

    Thanks a lot.

    I have 2 small questions

    set_time_limit(0);
    @readfile('abc.exe');

    1. Why a set time out has used here?
    2. what is that '@' tell in php

  4. #4
    SitePoint Enthusiast SecondV's Avatar
    Join Date
    Jan 2006
    Location
    Kentucky
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by afridy View Post
    Hai Dan,

    Thanks a lot.

    I have 2 small questions

    set_time_limit(0);
    @readfile('abc.exe');

    1. Why a set time out has used here?
    2. what is that '@' tell in php
    1.) Because .exe's can be very large (readfile() will read the file, then output it.. which can easily surpass php's maximum execution time
    2.) @ will suppress errors.

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Thanks SecondV

  6. #6
    SitePoint Enthusiast SecondV's Avatar
    Join Date
    Jan 2006
    Location
    Kentucky
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem.


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
  •