分享php如何现实强制更新图片缓存的方法(附代码)
分类:PHP_Python| 发布:佚名| 查看: | 发表时间:2015/6/28
php强制更新图片缓存的具体实现方法如下:
代码如下:/** 强制更新图片缓存
* @param Array $files 要更新的图片
* @param int $version 版本
*/
function force_reload_file($files=array(), $version=0){
$html = '';
if(!isset($_COOKIE['force_reload_page_'.$version])){ // 判断是否已更新过
setcookie('force_reload_page_'.$version, true, time()+2592000);
$html .= '
$html .= 'window.onload = function(){'."\r\n";
$html .= 'setTimeout(function(){window.location.reload(true); },1000);'."\r\n";
$html .= '}'."\r\n";
$html .= '';
echo $html;
exit();
}else{ // 读取图片一次,针对chrome优化
if($files){
$html .= '
$html .= "\r\n";
$html .= '';
}
}
return $html;
}
// 调用方法
$files = array(
'images/1.jpg',
'images/2.jpg',
'images/3.jpg',
'images/4.jpg'
);
$html = force_reload_file($files, 1);
echo $html;