Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * @author: unknown
  5. */
  6.  
  7. /**
  8. * Simulates a "wget url" and do not buffer data in the memory in order
  9. * to avoid thouse problems on large files.
  10. *
  11. * @param string $file_source
  12. * @param string $file_target
  13. * @return bool
  14. */
  15. function download($file_source, $file_target)
  16. {
  17. $rh = fopen($file_source, 'rb');
  18. $wh = fopen($file_target, 'wb');
  19.  
  20. // error reading or opening file
  21. if ($rh===false || $wh===false) return false;
  22.  
  23. while (! feof($rh) )
  24. {
  25. // 'Download error: Cannot write to file ('.$file_target.')';
  26. if (fwrite($wh, fread($rh, 1024)) === FALSE) return false;
  27. }
  28.  
  29. fclose($rh);
  30. fclose($wh);
  31.  
  32. // No error
  33. return true;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement