Simple download page with cache


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.