Tuesday, February 14, 2006

Download a file through server

Here is a small little trick... to solve the problem when your download speed is slow.

<?php

if (isset($_GET['d'])){
$pos = strpos($_GET['d'],"http://");
if (
$pos==0 && $pos!==false){
header('Content-Disposition: attachment;');
readfile($_GET['d']);
}
}

?>


What it does is it uses the server where the PHP file resides on to download the file, through the particular server, and then form the server to your computer. This can significantly improve download speed if the server is near to you or where the file is on. The server will most likely have higher bandwidth... and this can be used to speed up the transfer rate.

Of course, there are other uses as well... like in China... where some websites are censored. So the trick will be to get to a website that is not censored (like some US hosting websites) and then download the file of that website. Its not hard to create a web-based proxy-internet-explorer of some sort with PHP.

No comments: