Solved

PHP Header - download a .exe

Posted on 2004-08-19
6
1,290 Views
Last Modified: 2008-03-17
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.
0
Comment
Question by:rudyflyer
  • 4
  • 2
6 Comments
 
LVL 27

Expert Comment

by:Diablo84
ID: 11843774
header("Content-type: application/octet-stream exe");
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 200 total points
ID: 11843872
even better...

if($_GET['file'] == "file.exe") {
 $file = "/home/dir1/dir2/file.exe";
}

header("Content-type: application/octet-stream exe");
header("Content-Length: ".filesize($file));
readfile($file);
exit();
0
 

Author Comment

by:rudyflyer
ID: 11844024
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:Diablo84
ID: 11844422
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.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11844470
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
0
 

Author Comment

by:rudyflyer
ID: 11849015
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now