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';
$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'){
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);
}
the problem is the file that I downloaded is always the first pdf name from database
can you help me fix my code?