Posted By

zayyarphone on 05/13/11


Tagged

php image download


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tux-world


php image download


 / Published in: PHP
 

  1. function image_download($file_source, $file_target)
  2. {
  3. // prepare
  4. $file_source = str_replace(' ', '%20', html_entity_decode($file_source)); // fix url format
  5. if (file_exists($file_target)) chmod($file_target, 0777); // add write permission
  6.  
  7. // opne files
  8. if (($rh = fopen($file_source, 'rb')) === FALSE) return false; // fopen() handles
  9. if (($wh = fopen($file_target, 'wb')) === FALSE) return false; // error messages.
  10.  
  11. // read & write
  12. while (!feof($rh))
  13. {
  14. if (fwrite($wh, fread($rh, 1024)) === FALSE)
  15. {
  16. // unable to write to file, possibly
  17. // because the harddrive has filled up
  18. fclose($rh);
  19. fclose($wh);
  20. return false;
  21. }
  22. }
  23.  
  24. // close files
  25. fclose($rh);
  26. fclose($wh);
  27. return true;
  28. }

Report this snippet  

You need to login to post a comment.