Solved

PHP Header - download a .exe

Posted on 2004-08-19
6
1,292 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sort Multidimensional Array 11 34
PHP7 and Sql Server Windows 2008 R2 13 85
PHP: concatenate query 12 35
Convert html page to a php post email form automatically? 10 24
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

20 Experts available now in Live!

Get 1:1 Help Now