本文介绍了如何避免浏览器缓存使用Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
面对与浏览器缓存相关的问题。
Facing issue related to browser chache.
function doUpload(){
$data['includeView'] = "profileconfirm";
$config['upload_path'] = './img/images/uploaded/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '5000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_ext'] =".jpeg";
$config['file_name'] = $profileId.$config['file_ext'];
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
$query = null ;
if ( ! $this->upload->do_upload()){
// Error here
}else{
// Image uploaded sucess fully
// $profile - business logic to populate $profile
$data['PROFILE_DETAILS'] = $profile;
$this->load->view('index', $data);
}
此方法用于图像上传。
this method is used for image upload. After successful image upload, it loads index view page, which internally includes profileconfirm view page.
但是在profileconfirm页面,新上传的图片将不会反映。
But on profileconfirm page new uploaded image is not going to reflect. Some times it works fine, but some times not, this is happen most of the times.
请帮助
推荐答案
您可以向客户端发送适当的标头以禁用缓存:
You can send proper headers to the client to disable the cache:
....
$this->output->set_header("HTTP/1.0 200 OK");
$this->output->set_header("HTTP/1.1 200 OK");
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
$this->load->view('index', $data);
注意:输出类自动初始化
Note: Output class is initialized automatically
这篇关于如何避免浏览器缓存使用Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!