direct download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

direct download

Post by bouncer »

hi there,

can someone tell me how can i make a script 'index.php' that contain a direct link to download a file inside the same folder of 'index.php'.

like those links that you insert in your browser and immediatly appears a download windows without opening any page, i hope that you understand what i'm trying to do. :roll:

i have this in my 'index.php'

Code: Select all

 
header('Content-type: application/exe');
 
header('Content-Disposition: attachment; filename="file.exe"');
 
readfile('file.exe');
 
thanks in advance
User avatar
Mds
Forum Contributor
Posts: 110
Joined: Tue Apr 22, 2008 8:56 pm
Contact:

Re: direct download

Post by Mds »

Hi

you can use this code :
redirect("file.exe", 0);

function redirect($url, $time)
{
$table = "
<table width=\"60%\" border=\"1\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bordercolor=\"#959595\" bgcolor=\"#ECE9D8\">
<tr>
<td align=\"center\">
<br />
Please Wait ....
<br /><br />
</td>
</tr>
</table>";

$javascript ="
<script type=\"text/javascript\" language=\"javascrip\">
setTimeout(\"redirect()\",$time);
function redirect()
{
window.location = \"$url\";
}
</script>";

print($javascript);
print($table);

exit;
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: direct download

Post by John Cartwright »

There are tons of good snippets around here, search around using the term "force download".

Hint:

Code: Select all

header('Content-Type: application/force-download');
I wouldn't rely on javascript either for downloading, as Mds's does.
User avatar
Mds
Forum Contributor
Posts: 110
Joined: Tue Apr 22, 2008 8:56 pm
Contact:

Re: direct download

Post by Mds »

Hi,
see this link, probably useful for you

CURL, Client URL Library Functions
Post Reply