Topspeed
asked on
Download script (php) .
I need a php script to download files up to 100 mb from other servers like rapidshare to my http server?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forgot to say that it works in a buffer manner, with buffer set to 1024 bytes (you can change that to whatever you like). Also, you might need to change socket and/or connection and/or execution timeouts depending on the files size and the server connection bandwidth...
ASKER
Thank you. The script worked for me but i would like to ask if you can make the script to enter the links directly from the browser And not editing the script every time i want to download a file.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------
<?php
$source = ""; $target = ""; $result = "";
if (isset($_GET['download']))
{
$source = stripslashes($_GET['source ']);
$target = stripslashes($_GET['target ']);
$result = download($source, $target);
if ($result)
$result = "<b>Downloaded:</b><br>$so urce<br>$t arget<br>" ;
else
$result = "<b>Failed:</b><br>$source <br>$targe t<br>";
}
?>
<html>
<head><title></title></hea d>
<body>
<center>
<br><?php echo $result; ?><br>
<form action="" method="get">
<input type="hidden" name="download" value="1">
Source:<br><input type="text" name="source" value="<?php echo $source; ?>"><br>
Target:<br><input type="text" name="target" value="<?php echo $target; ?>"><br>
<br><input type="submit"> <input type="button" value="Reload" onclick="window.location=' ?'">
</form>
</center>
</body>
</html>
<?php
function download($file_source, $file_target)
{
// prepare
$file_source = str_replace(' ', '%20', html_entity_decode($file_s ource)); // fix url format
if (file_exists($file_target) ) chmod($file_target, 0777); // add write permission
// opne files
if (($rh = fopen($file_source, 'rb')) === FALSE) return false; // fopen() handles
if (($wh = fopen($file_target, 'wb')) === FALSE) return false; // error messages.
// read & write
while (!feof($rh))
{
if (fwrite($wh, fread($rh, 1024)) === FALSE)
{
// unable to write to file, possibly
// because the harddrive has filled up
fclose($rh);
fclose($wh);
return false;
}
}
// close files
fclose($rh);
fclose($wh);
return true;
}
?>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------
<?php
$source = ""; $target = ""; $result = "";
if (isset($_GET['download']))
{
$source = stripslashes($_GET['source
$target = stripslashes($_GET['target
$result = download($source, $target);
if ($result)
$result = "<b>Downloaded:</b><br>$so
else
$result = "<b>Failed:</b><br>$source
}
?>
<html>
<head><title></title></hea
<body>
<center>
<br><?php echo $result; ?><br>
<form action="" method="get">
<input type="hidden" name="download" value="1">
Source:<br><input type="text" name="source" value="<?php echo $source; ?>"><br>
Target:<br><input type="text" name="target" value="<?php echo $target; ?>"><br>
<br><input type="submit"> <input
</form>
</center>
</body>
</html>
<?php
function download($file_source, $file_target)
{
// prepare
$file_source = str_replace(' ', '%20', html_entity_decode($file_s
if (file_exists($file_target)
// opne files
if (($rh = fopen($file_source, 'rb')) === FALSE) return false; // fopen() handles
if (($wh = fopen($file_target, 'wb')) === FALSE) return false; // error messages.
// read & write
while (!feof($rh))
{
if (fwrite($wh, fread($rh, 1024)) === FALSE)
{
// unable to write to file, possibly
// because the harddrive has filled up
fclose($rh);
fclose($wh);
return false;
}
}
// close files
fclose($rh);
fclose($wh);
return true;
}
?>
--------------------------
Just paste that into a single php page, it doesn't matter what you name it. Also, I think it would be better if you change 1024 bytes buffer to something a bit bigger, should work faster, for example: 8Kb (8192 bytes).
ASKER
Yeas man.
Thank you very much. This is what is was looking for.
Thank you very much. This is what is was looking for.
A better solution would be to grab yourself a script called Rapidleech which is specifically built for the purpose of downloading files hosted on filesharing sites.
http://www.rapidleech.com/index.php?showforum=10
The benefit of this is that it is constantly updated and also includes features such as download timers, captcha codes etc
http://www.rapidleech.com/index.php?showforum=10
The benefit of this is that it is constantly updated and also includes features such as download timers, captcha codes etc