Link to home
Start Free TrialLog in
Avatar of rudyflyer
rudyflyer

asked on

PHP Header - download a .exe

Hello,

I have the following code which downloads a .exe

<?PHP

if($_GET['file'] == file.exe)
      readfile('/home/dir1/dir2/file.exe')

?>

I believe I need to put "header ('Content-type....something something).  I do not know what header to use.  Can you please help by suggesting the appropriate header.

Thanks.
Avatar of Diablo84
Diablo84

header("Content-type: application/octet-stream exe");
ASKER CERTIFIED SOLUTION
Avatar of Diablo84
Diablo84

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rudyflyer

ASKER

Diablo84.  Thank you.  But I seem to have another problem.  I have the .exe in a different directory away from the Web directory.  I did this so someone could not browser to www.website.com/file.exe and download it before registering to receive it.  Anyway, using your code above I receive a pop-up alert which reads "Internet Explorer was unable to this Internet site.  The requested site is either unavialable or cannot be found.  Please try again".

I have increased points to 200 since I am encountering a different problem.

Thank you
Im not sure that you can access files outside of the web directory via http

You may wish to instead use http authentication to restrict casual users downloading the file but still have the executable within the web directory.

Theres an example of that in conjunction with php here: http://www.zend.com/manual/features.http-auth.php

However i expect you can get more information regarding protecting files online in the HTML TA, its something i have limited knowledge of and so cannot provide you with as much information as i would like.
heres another couple of links that may help you:

authentication using a .htaccess file: http://hoohoo.ncsa.uiuc.edu/docs/tutorials/user.html
authentication using php tutorial: http://www.sitepoint.com/article/http-authentication-php
Diablo84,

The answer I accepted worked nicely.  I had to make a couple tweaks to it.  The reason I was receiving that error was because I was calling a session_start() before the headers.  That is what caused the error.

Thanks again.