Welcome Guest, Not a member yet? Register   Sign In
Create a download manager with the helper "Download" in CodeIgniter
#1

[eluser]masentinel900[/eluser]
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:

Code:
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=''>&lt;input name='opcion-res' type='radio' align='center'/&gt;&lt;/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.
#2

[eluser]Massaki[/eluser]
How does the 'download' Controller works? Does it get the file path from the DB as from an ID, alias or another identifier?
#3

[eluser]masentinel900[/eluser]
Hello, Thanks my friend..

Basically my Download controller is this.

Code:
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.

Code:
<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

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

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

[eluser]Massaki[/eluser]
Got it.
So you must do this:
Code:
$content.="
   <tr>
    <td id=''>&lt;input name='opcion-res' type='radio' align='center'/&gt;&lt;/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:
Code:
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
#5

[eluser]masentinel900[/eluser]
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

Code:
var a = document.getElementById('some');
if(a.onclick)
{
   alert(a.value);
}

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




Theme © iAndrew 2016 - Forum software by © MyBB