Download image from the name saved in the Codeigniter ajax database?

0

Currently with a plugin upload the image to my server, with this plugin (Dropzone.js) carturo the path of this file. I do all this to avoid having to upload the tax file to the database and I only keep the name.

Example upload file capture

var nameAdjunto  = "/var/www/html/cartoni/uploads/" +myDropzone.files[0].name;
alert(nameAdjunto);
  

returns /var/www/html/cartoni/uploads/captura.PNG

The nameAdjunto value I keep in the database

Now I call that image

Model

public function listar($table)
    {
        $data= $this->db->get($table);
        return $data->result();
    }

driver:

$data['uploads'] = $this->Model->listar('tabla_upload);

How can I download the file just by taking the route?

How do I build the url to download the file?

 <?php echo var_dump($uploads->name) ?>

I hope you have explained to me very well thank you!

    
asked by Javier Antonio Aguayo Aguilar 17.04.2017 в 06:13
source

1 answer

1

Seeing in the codeigniter documentation there is a helper function called force_download() which it receives as parameters the name of the file and the file. If you already know the file path, you should only pass as the first parameter and in your second parameter you pass null :

$this->load->helper('download'); //primero se carga el helper force_download('./uploads/captura.png',NULL);

This works if your index.php file is in the /cartoni/ folder, codeigniter creates the route.

    
answered by 17.04.2017 в 08:20