php image download


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.