#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    9
    Rep Power
    0
    I am trying to create a page which has no html code, just plain php. This page is supposed to read an .exe and send it to the whoever request the page. The code go like this:

    header("Content-type: application/octet-stream");
    if (!($myFile = fopen("path of file", "r"))) {
    // cannot open file
    }
    // send the entire file to browser
    fpassthru($myFile);

    What the client received is just text/ascii dump on the browser. What I am expecting is a prompt to appear asking when the client wish to save the file to. Can anyone advice whether I have done it wrongly or there is a better way of doing it. Thank you in advance!
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Actually, you are over-complicating this problem. You done't need to open a stream for this file at all, just provide a redirection to it. You are instructing PHP to open the contents, which then become text, as far as PHP knows.

    On a regular static HTML web site, you can simply provide a link to a .EXE file and the webserver will prompt the browser automatically (based on its MIME configuration).

    So... in your PHP page, you could simply use
    <meta http-equiv="refresh" content="0;URL=<% echo $myFile; %>">

    Again, be sure that your web server is configured properly.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    9
    Rep Power
    0
    rycamor, thank you for the response. B4 I go any further, I would like to say my main purpose in creating that php page for the download. My intention was to hide the actual location of the file, and I come up with this idea. Maybe its not a good idea , but it was my first thought. The header function keep complaining abt cannot resend header again. I wonder is there a way to reset the header? Or you have a better the solution to my problem?
  6. #4
  7. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Actually I tried you code and it worked on my server, except for one small problem: the file I was prompted to save was named after the .php page, and I had to rename it with a .exe extension. Other than that, it saved as an executable and ran fine. Try http://deepblue.theup-tick.com/~rick/getlemmings.php (it downloads a flash movie called lemmings.exe)

    I think your webserver configuration needs some tweaking. Are you using Apache?

    I will see if I can figure out a way to prompt with the right filename for download.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    9
    Rep Power
    0
    Rycamor,
    I tried the link u have provided and it work fine in Netscape, but when it come to MSIE... :/ ... the stupid browser was showing those text dump instead of a prompt to save the file to somewhere. I have to make sure my script works for both netscape and msie
  10. #6
  11. No Profile Picture
    worshipper of DOT
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Halmstad, Sweden
    Posts
    35
    Rep Power
    15
    rycamor:

    i tried that link too (in MSIE 5), and didn't even get a prompt to save the file, instead it just started downloading it .. god knows where it went, but i noticed it was saved as "lemmings.php" ..



    [This message has been edited by closecut (edited May 17, 2000).]
  12. #7
  13. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    phobos-

    It works fine for me on both IE5 and Netscape3 and 4. What version of IE are you using?

    closecut-

    I don't know how a browser could just start downloading something without prompting, but that scares me. Another reason not to use IE most of the time!?!? Search for lemmings.php and rename it to lemmings.exe and see if it works.

    Still haven't had had the time to figure out how to prompt with an .exe extension.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    9
    Rep Power
    0
    rycamor,
    I am using MSIE 5. Version is 5.00.2614.3500

    When I click on the link that u have provided...text dump was on my screen :/

  16. #9
  17. No Profile Picture
    damari
    Guest
    Devshed Newbie (0 - 499 posts)
    header("Content-disposition: filename=thefilename.exe");
    header("Content-type: application/octetstream");

    should send the file as thefilename.exe !

    Regards

    ------------------

Similar Threads

  1. Mysql problem.
    By Nik in forum MySQL Help
    Replies: 54
    Last Post: December 21st, 2006, 06:02 PM
  2. General info on email and Postfix server
    By volks73 in forum Mail Server Help
    Replies: 3
    Last Post: February 8th, 2004, 04:38 PM
  3. Replies: 0
    Last Post: January 6th, 2004, 02:23 PM
  4. how to download a complete folder from server to clients machine
    By Programmer123 in forum ASP Programming
    Replies: 2
    Last Post: January 6th, 2004, 12:33 AM
  5. Replies: 17
    Last Post: January 2nd, 2004, 03:07 AM

IMN logo majestic logo threadwatch logo seochat tools logo