Php 在CI中强制下载后如何刷新页面
如何在codeigniter controller中的Php 在CI中强制下载后如何刷新页面,php,codeigniter,Php,Codeigniter,如何在codeigniter controller中的force_download后刷新页面,以下是我的控制器功能。调用force\u下载后,它不执行任何功能 public function download(){ $this->load->library('user_agent'); $this->load->helper('download'); $file_id = $this->uri->segment(3); if(
force_download
后刷新页面,以下是我的控制器功能。调用force\u下载后,它不执行任何功能
public function download(){
$this->load->library('user_agent');
$this->load->helper('download');
$file_id = $this->uri->segment(3);
if(!empty($file_id)){
//get file info from database
$fileInfo = $this->Files->get_file($file_id);
foreach ($fileInfo as $key => $object) {
$download_direc = $object->file_direc;
}
//download file
force_download($download_direc, NULL);
//increment the download value by 1 in the db
$this->Files->update_download($file_id);
//refresh the page
redirect($this->agent->referrer());
}
}
谢谢你你可以试试这个。我希望它能帮助你
public function download($fileName = NULL) {
if ($fileName) {
$file = realpath ( "download" ) . "\\" . $fileName;
if (file_exists ( $file )) {
$data = file_get_contents ( $file );
force_download ( $fileName, $data );
} else {
redirect ( base_url () );
}
}
}
你可以试试这个。我希望它能帮助你
public function download($fileName = NULL) {
if ($fileName) {
$file = realpath ( "download" ) . "\\" . $fileName;
if (file_exists ( $file )) {
$data = file_get_contents ( $file );
force_download ( $fileName, $data );
} else {
redirect ( base_url () );
}
}
}
当用户单击锚定链接或按钮下载文件时,在“查看”页面上。
只需获取该按钮的id,并将jQuery间隔设置为2500-3000,这样页面将在2.5-3秒后刷新。当用户单击锚链接或按钮下载文件时,在查看页面上。
只需获取该按钮的id,并将jQuery间隔设置为2500-3000,这样页面将在2.5-3秒后刷新。重定向($\u服务器['REQUEST\u URI','refresh');不工作,在执行force_download
后,它似乎无法再重定向。您甚至不必执行此操作,因为您只需返回单击下载按钮的初始页面(例如链接到下载方法的按钮)。基本上,浏览器实现了它的“文件”,并将其视为任何其他下载。所以你应该保持一致。删除重定向。您没有看到我所描述的这种情况吗?重定向($_SERVER['REQUEST\u URI'],'refresh');不工作,在执行force_download
后,它似乎无法再重定向。您甚至不必执行此操作,因为您只需返回单击下载按钮的初始页面(例如链接到下载方法的按钮)。基本上,浏览器实现了它的“文件”,并将其视为任何其他下载。所以你应该保持一致。删除重定向。你没有看到我描述的这种情况吗?非常感谢@Ankesh,它起作用了,你节省了我的时间。非常感谢@Ankesh,它起作用了,你节省了我的时间