kwangu

DOWNLOAD FILE USING CI

Jun 29th, 2015
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. CONTROLLER
  2. class Download extends CI_Controller {
  3.  
  4.     public function __construct() {
  5.         parent::__construct();
  6.     }
  7.    
  8.     public function index(){
  9.            $this->load->model('files_model');
  10.           $data['pdfs'] = $this->files_model->get_pdf_files();
  11.           $this->load->view('download/dynamic',$data);
  12.          
  13.         }  
  14.  
  15.     public function download_file($name){
  16.        
  17.         $this->load->helper('download'); //load helper
  18.         $path = file_get_contents('/uploads/docs/'.$name); // Read the file's contents
  19.        
  20.         force_download($name, $path);
  21.        
  22.         }
  23.  
  24. }
  25. VIEW
  26.  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  27. <html xmlns="http://www.w3.org/1999/xhtml">
  28. <head>
  29. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  30. <title>Download Document</title>
  31. </head>
  32.  
  33. <body>
  34.   <ul>
  35.   <?php
  36.   //var_dump($pdfs);
  37. //echo $pdfs[0]->file_name;
  38.    foreach($pdfs as $row):
  39.  ?>          
  40.  <?php
  41.  echo "<li style=\"padding-bottom:10px;\"><a href='/download/download_file/".$row->file_name."'>Download</a></li>";?>    
  42. <?php endforeach;?>
  43.  </ul>  
  44. </body>
  45. </html>
Add Comment
Please, Sign In to add comment