Link to home
Start Free TrialLog in
Avatar of Topspeed
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
Avatar of den4b
den4b
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
Avatar of Topspeed
Topspeed

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>$source<br>$target<br>";
            else
                  $result = "<b>Failed:</b><br>$source<br>$target<br>";
      }
?>


<html>
<head><title></title></head>
<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">&nbsp;<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_source)); // 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;
}
?>
-------------------------------------------------------------------------------------
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).
Yeas man.

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