Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I make a download function to download pdf based on filename that has already inserted on database and this is my function:
PHP
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:
PHP
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);
    }



PHP
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?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900