Hi guys just a quick question...when you upload a file to the database and the file name is saved and encrypted in codeigniter how do i make a link that when clicked will download the file associated with the id of the table entry?

for instance this is my view file:

                        <?php foreach ($cvs as $row) {
                            <td><?php echo $row['appID']; ?></td>
                            <td><?php echo $row['name']; ?></td>
                            <td><?php echo $row['email']; ?></td>
                            <td><?php echo $row['contact']; ?></td>
                            <td><?php echo Date::format($row['date_added']) ?></td>
                            <td><a href="<?php echo $row['cv']?>">Download CV</a></td>
                        <?php } ?>

not all the code but that is the section i want the link to display as you can see it is showing a link but when clicked it does not download that file from the server how do i fix this. My framework is codeigniter 3.0

Thanks for your input


Hi, you can create a method in your controller, search the database table and use the Download helper, for example:

public function download($id)
    # load download helper

    # search for filename by id
    $this->db->where('id', $id);
    $q = $this->db->get('tablename');

    # if exists continue
    if($q->num_rows() > 0)
        $row  = $q->row();
        $file = FCPATH . 'files/'. $row->filename;
            force_download($file, NULL);


Then simply create a link that points to the above method, for example:


Docs: http://www.codeigniter.com/user_guide/helpers/download_helper.html

helooo i have a some probleam for downloading a file from database. please help me how to download file from database and please send me the helper code for downloading...


Hello, please provide more information (e.g. are you using CodeIgniter?) and your current code, also open your own thread.