Welcome Guest, Not a member yet? Register   Sign In
Sending file path to controller
#3

[eluser]minimal design[/eluser]
The way I do it on my site goes something like that:

site.com/downloads/get_file/2

where "2" is the id of the file in the DB.

All my downloads are stored in the same directory so in your case you might have to store path of file in DB too.

Code:
function get_file($id) {
    // you get the file name + path + whatever info I need from the DB.
    // The model will vary a lot depending on setup so you'll have to figure that part...
    $f = $this->downloads_model->get_file_info($id);
    // then you download the file like that
    $name = $f['file_name']; // name of downloaded file
    $f_uri = '/downloads/'.$name;
    $file = file_get_contents($f_uri); // need to read file's contents to pass to force_download()
    force_download($name, $file);
}

You should also check out the new file helper... Haven't played with it yet, but it might make things even simpler.

EDIT:

here's what the model could look like, to give you a basic idea:


Code:
function get_file_info($id) {
        $this->db->select('file_name, file_path, download_count');
        $query = $this->db->get_where($this->dl_table, array('id' => $id), 1);
        if ($query->num_rows() == 1) {
            $file = $query->row_array();
        }
        return $file;
    }


Messages In This Thread
Sending file path to controller - by El Forum - 06-03-2008, 05:20 PM
Sending file path to controller - by El Forum - 06-03-2008, 05:26 PM
Sending file path to controller - by El Forum - 06-03-2008, 05:33 PM
Sending file path to controller - by El Forum - 06-03-2008, 05:39 PM
Sending file path to controller - by El Forum - 06-03-2008, 05:41 PM
Sending file path to controller - by El Forum - 06-03-2008, 05:44 PM
Sending file path to controller - by El Forum - 06-03-2008, 05:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB