Solved

PHP Header - download a .exe

Posted on 2004-08-19
6
1,310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

632 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