0

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) {
                        ?>
                        <tr>
                            <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>
                        </tr>
                        </tbody>
                        <?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

Riaan

Edited by Ventech_IT

3
Contributors
3
Replies
18
Views
1 Year
Discussion Span
Last Post by cereal
0

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
    $this->load->helper('download');

    # search for filename by id
    $this->db->select('filename');
    $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;
        if(file_exists($file))
            force_download($file, NULL);
    }

    else
        show_404();
}

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

http://site.tld/controller/download/123 

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

Edited by cereal

0

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...
thankyou

0

@mohammad

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.