本文介绍了codeigniter从数据库下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我根据已插入数据库的文件名下载pdf下载函数,这是我的功能:
I make a download function to download pdf based on filename that has already inserted on database and this is my function:
function download($offset=0,$order_column='judul',$order_type='asc'){
$this->load->helper('download');
if(empty($offset)) $offset=0;
if(empty($order_column)) $order_column='judul';
if(empty($order_type)) $order_type='asc';
//load data
$data=$this->m_ebook->semua($this->limit,$offset,$order_column,$order_type)->result();
$config['total_rows']=$this->m_ebook->jumlah();
$config['per_page']=$this->limit;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$data['pagination']=$this->pagination->create_links();
foreach ($data as $row)
{
$data=file_get_contents("./assets/files/".$row->file);
$name = 'download.pdf';
force_download($name,$data);
}
}
这些是我的型号:
these are my models:
function semua($limit=10,$offset=0,$order_column='',$order_type='asc'){
// $db1 = $this->load->database('default',TRUE);
if(empty($order_column) || empty($order_type))
$this->db->order_by($this->primary,'asc');
else
$this->db->order_by($order_column,$order_type);
return $this->db->get($this->table,$limit,$offset);
}
function jumlah(){
return $this->db->count_all($this->table);
}
问题是我下载的文件始终是数据库中的第一个pdf名称
你可以帮我修改我的代码吗?
the problem is the file that I downloaded is always the first pdf name from database
can you help me fix my code?
推荐答案
这篇关于codeigniter从数据库下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!