• 0

[PHP] Set exe to auto download


Question

Hey,

Making a website for where i work, and there is a .exe file that we need people to download.

its a file that lets us set up a remote connection to their PC, so it really needs to stay as a exe file as well, because these people are stupid.

I've got some PHP code that i thought would make it download when you click a link, but it seems to download the php file instead.

i dont really understand how this auto download thing works, so if someone knows how to make this work, i would appreciate the help :D

<?php
header('Content-disposition: attachment; filename:DLA-Remote-Support.exe');
header('Content-type: application/octet-stream');
readfile('DLA-Remote-Support.exe');
?>

Thanks in advance

Im an idiot!

PHP isnt always the best solution. Some times you just gotta stick with good ol' HTML :D

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

What's wrong with just having an <a> href link to the exe?

im such an idiot!

as soon as i read back what i had put, i realised that. was just about to edit my post to say im an idiot :(

was going completely the wrong way about things.

Link to comment
Share on other sites

  • 0

sounds like apache/your web server isnt serving it properly.

add a mime type for .exe file types to your server config or a .htaccess file if you use apache.

thats if you were going to do it the way you said in your first post :p

Link to comment
Share on other sites

  • 0

Yeh a href is definatly a better idea unless you going to add a counter and tell the person your about to download something onto there computr (yes i know they will get a save dialog) because if i was to load a page and it tried to automatically download something on my computer wihtout warning i would leave the site, delete the download and i may even write a not so nice email.

Link to comment
Share on other sites

  • 0

Yeh a href is definatly a better idea unless you going to add a counter and tell the person your about to download something onto there computr (yes i know they will get a save dialog) because if i was to load a page and it tried to automatically download something on my computer wihtout warning i would leave the site, delete the download and i may even write a not so nice email.

Well... in a situation like mine where I do roughly the same thing 30 times a day and 28 out of those 30 times I'm explaining to the person why they should click "Run" on the file i'm telling them to download. It's a hassle... A big one. I'd rather have it download immediately and run itself, especially if it's only being accessed on my corporate intranet.

Link to comment
Share on other sites

  • 0

Well... in a situation like mine where I do roughly the same thing 30 times a day and 28 out of those 30 times I'm explaining to the person why they should click "Run" on the file i'm telling them to download. It's a hassle... A big one. I'd rather have it download immediately and run itself, especially if it's only being accessed on my corporate intranet.

You might do the same thing 30x a day, but if my grandad contacted me and said "im just on xxx website and im being asked to download xxx and ive clicked nothing what should i do?" my response would be "click cancel" Like i said some warning before hand, or a a href link is best i never download anything thats automatic without some warning first would you download a file just because its an automatic download? Even it it is on an intranet does not mean its not a bad file!

Link to comment
Share on other sites

  • 0

Hello,

I was searching for some tips for downloading files with php, and I found your forums.

Here is my experience:

When using something like this

&lt;?php
header('Content-disposition: attachment; filename:DLA-Remote-Support.exe');
header('Content-type: application/octet-stream');
readfile('DLA-Remote-Support.exe');
?&gt;

I can download zip and rar files with no problems, but when it comes to exe files, when downloaded, they can't open. I get some error message.

But when using

header("Location: file.exe")

it works well when downloaded. But, there is other problem. If I refresh (probably close too) the page, while downloading, it stops.

So, I still didn't find a perfect solution, I use combination of these two.

DomZ asked what's wrong with ordinary <a> link. It is better to use automatic download with php, 'cause in that case you can record some statistics for downloaded file.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.