PHP Cached Download Function
Aug 4, 2008 · 1 minute readCategory: php
This is post is now quite old and the the information it contains may be out of date or innacurate.
If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub
This function allows you to do exactly that - check it out:
$cache_days = 1;
$cache_days = $cache_days * (24*60*60);
function cached_download($remote, $local){
$cache_days = $GLOBALS['cache_days'];
if(file_exists($local) && (filemtime($local) > (time() - $cache_days))){
// we have a local copy that is less than $cache_days old
echo '
<h3>Using Cached - Last Downloaded ' . date('H:m:s d/m/Y', filemtime($local) . '</h3>
';
}else{
echo '
<h3>Downloading Now...</h3>
';
flush();
copy($remote, $local);
}
}