Posted By

Keef on 04/28/09


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

Jdub7
Dean_IconWeb
BrianCoyDesign
ash_hitch


Simple download page with cache


 / Published in: PHP
 

  1. function download($url, $cache_time=0)
  2. {
  3. $cache_file = sys_get_temp_dir(). '/'. sha1($url);
  4.  
  5. if (file_exists($cache_file) && (time() - @filemtime($cache_file) < $cache_time))
  6. {
  7. $file = file_get_contents($cache_file);
  8. } else {
  9. $file = file_get_contents($url);
  10. file_put_contents($cache_file, $file);
  11. }
  12.  
  13. return $file;
  14. }

Report this snippet  

You need to login to post a comment.