手机
当前位置:查字典教程网 >编程开发 >php教程 >php强制更新图片缓存的方法
php强制更新图片缓存的方法
摘要:本文实例讲述了php强制更新图片缓存的方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:/**強制更新圖片緩存*@paramA...

本文实例讲述了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 .= '<script type="text/javascript">'."rn";

$html .= 'window.onload = function(){'."rn";

$html .= 'setTimeout(function(){window.location.reload(true); },1000);'."rn";

$html .= '}'."rn";

$html .= '</script>';

echo $html;

exit();

}else{ // 讀取圖片一次,針對chrome優化

if($files){

$html .= '<script type="text/javascript">'."rn";

$html .= "<!--rn";

for($i=0,$max=count($files); $i<$max; $i++){

$html .= 'var force_reload_file_'.$i.' =new Image()'."rn";

$html .= 'force_reload_file_'.$i.'.src="'.$files[$i].'"'."rn";

}

$html .= "-->rn";

$html .= '</script>';

}

}

return $html;

}

// 调用方法

$files = array(

'images/1.jpg',

'images/2.jpg',

'images/3.jpg',

'images/4.jpg'

);

$html = force_reload_file($files, 1);

echo $html;

希望本文所述对大家的php程序设计有所帮助。

【php强制更新图片缓存的方法】相关文章:

php生成图片缩略图的方法

PHP 判断数组是否为空的5大方法

php将12小时制转换成24小时制的方法

php获取网页上所有链接的方法

php计算整个目录大小的方法

smarty模板判断数组为空的方法

PHP文本数据库的搜索方法

PHP实现多线程的两个方法

php实现图片转换成ASCII码的方法

php一个解析字符串排列数组的方法

精品推荐
分类导航