EllisLab text mark
Advanced Search
     
Create a download manager with the helper “Download” in CodeIgniter
Posted: 20 November 2012 10:18 AM   [ Ignore ]
Joined: 2012-10-12
57 posts

Hello everybody.

Now I’m creating a download manager of the next way:

1: In the model file I made the query selection to my DB.
2: In a controller I get the data from my DB and I organize it trought of a foreach loop seting the data in a table and then show it in a output function.
3: In my app when I look the table in the view, I see the data tabulate and paginate by 10 records. each record has 4 rows. the rows are the name, created by, date and a selected field.
  -When I onclick on the name of the record (LINK) the download start automatically, downloading the correponding file.
  ¡For this there are somy variables that I get but don’t show, which are the route of my file!.

All goes fine, But I’m truncated in what I don’t know how to send the selected route to my controller route.

Actually I have this:

if ($query->num_rows() > 0)
  
{
  
foreach($query->result_array() as $row)
  
{
   $data 
= array(
   
'fechacreacion' => $row['fechacreacion'],
   
'descripcion' => $row['descripcion'],
   
'codigoagencia' => $row['codigoagencia'],
   
'nombreacta' => $row['nombreacta'],
   
'rutaarchivo' => $row['rutaarchivo'],
   );
   
$content.="
   <tr>
    <td id=''><input name='opcion-res' type='radio' align='center'/></td>
    <td id=''><a href='download'>
$data[descripcion]</a></td>
    <td id=''>
$data[rutaarchivo]</td>
    <td id=''>
$data[fechacreacion]</td>
   </tr>
   "
;   
  
}
   $this
->session->set_userdata('logged_content'$data);  
  
}
  $this
->output->set_output($content); 

If someone has a better Idea of Howa could to be a download manager, I will thanks that let me know.

 

 
Posted: 20 November 2012 02:03 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-08-10
16 posts

How does the ‘download’ Controller works? Does it get the file path from the DB as from an ID, alias or another identifier?

 
Posted: 21 November 2012 10:54 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-10-12
57 posts

Hello, Thanks my friend..

Basically my Download controller is this.

function index()
 
{
  $data 
$this->session->userdata('logged_content');
  echo 
$data['rutaarchivo'];
  
/*
  $ruta = $data['rutaarchivo'];
  $this->load->helper('download');
  $data = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Online-App/filesFolder/" . $ruta);
  $name = $ruta;
  force_download($name, $data);
  */
 

This have the comentary because now I’m trying of just to show the variable, Is for test and when I get Ok I quit the “/*”.
Now I ask me if there a way of pass a variable with the controller. Ergo.

<a href='download/$data'></a

Or some like this for may get the value that has a row in the loop. I already tried of use

$this->session->set_userdata($data); 

But get the value of array but not of the loop.

 
Posted: 21 November 2012 11:50 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-08-10
16 posts

Got it.
So you must do this:

$content.="
   <tr>
    <td id=''><input name='opcion-res' type='radio' align='center'/></td>
    <td id=''><a href='download/
$data[rutaarchivo]'>$data[descripcion]</a></td>
    <td id=''>
$data[rutaarchivo]</td>
    <td id=''>
$data[fechacreacion]</td>
   </tr>
   "

Then, in the download controller:

function index($ruta// $ruta is the first parameter after the slash '/'
 
{
  
echo $ruta// Path to the chosen file 
  /*
  $ruta = $data['rutaarchivo'];
  $this->load->helper('download');
  $data = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Online-App/filesFolder/" . $ruta);
  $name = $ruta;
  force_download($name, $data);
  */
 

* En lugar de “download/$data[rutaarchivo]” use el ID del archivo. Así, el nombre o la ruta permanecen ocultos

 
Posted: 21 November 2012 12:06 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-10-12
57 posts

Hello.
I see your response and tryied to do it but, when I onclick in the link pass the variable through of URL and obvisuly find not nothing.

I was thinking if there the possibility of create some like in javascript “onselect”. I just need pass the variable inside the loop.

In javascript wil be like

var document.getElementById('some');
if(
a.onclick)
{
   alert(a
.value);

If do you can response in spanish there not problem, I speak spanish perfectly. Thanks