Solved

PHP Header - download a .exe

Posted on 2004-08-19
6
1,293 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 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