Page 1 of 1

direct download

Posted: Wed Apr 23, 2008 10:39 am
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

Re: direct download

Posted: Wed Apr 23, 2008 11:19 am
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;
}

Re: direct download

Posted: Wed Apr 23, 2008 11:39 am
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.

Re: direct download

Posted: Wed Apr 23, 2008 12:08 pm
by Mds
Hi,
see this link, probably useful for you

CURL, Client URL Library Functions