2076 Posts in 483 Topics- by 820 Members - Latest Member: akunp2

Pages: [1]   Go Down
  Print  
Author Topic: [PHP Code] Download Files HTTP and Put It into Local Target  (Read 642 times)
webmaster
Administrator
phpBB Guru
*****
Offline Offline

Posts: 924


hairulazami
View Profile WWW
« on: October 31, 2008, 09:41:34 AM »

Code:
<?
define ("_MAX_DOWNLOAD_RATE", 20.5*1024); //20kb / second

function putItNow($file_source, $file_target)
{
  // Preparations
  $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

  // Begin transfer
  if (($rh = fopen($file_source, 'rb')) === FALSE) { return false; } // fopen() handles
  if (($wh = fopen($file_target, 'wb')) === FALSE) { return false; } // error messages.
  while (!feof($rh))
  {
    // unable to write to file, possibly because the harddrive has filled up
    if (fwrite($wh, fread($rh, round(_MAX_DOWNLOAD_RATE))) === FALSE) { fclose($rh); fclose($wh); return false; }
  }

  // Finished without errors
  fflush($rh);
  fflush($wh);
  fclose($rh);
  fclose($wh);
  return true;
}

putItNow("http://www.buytemplates.net/img/display_images/thumbnails/s_blog256_01.jpg", "d:\dremi\s_blog256_01.jpg");
?>
Logged


Pages: [1]   Go Up
  Print  
 
Jump to: