Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONTROLLER
- class Download extends CI_Controller {
- public function __construct() {
- parent::__construct();
- }
- public function index(){
- $this->load->model('files_model');
- $data['pdfs'] = $this->files_model->get_pdf_files();
- $this->load->view('download/dynamic',$data);
- }
- public function download_file($name){
- $this->load->helper('download'); //load helper
- $path = file_get_contents('/uploads/docs/'.$name); // Read the file's contents
- force_download($name, $path);
- }
- }
- VIEW
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>Download Document</title>
- </head>
- <body>
- <ul>
- <?php
- //var_dump($pdfs);
- //echo $pdfs[0]->file_name;
- foreach($pdfs as $row):
- ?>
- <?php
- echo "<li style=\"padding-bottom:10px;\"><a href='/download/download_file/".$row->file_name."'>Download</a></li>";?>
- <?php endforeach;?>
- </ul>
- </body>
- </html>
Add Comment
Please, Sign In to add comment