Advertisement
uchuneno

Untitled

Feb 28th, 2020
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. View
  2. <form role="form" action="<?php echo base_url().'laporan'?>">
  3. <input type = "text" id="tahun" name="tahun" class="form-control" placeholder="Masukkan Tahun" required/>
  4. </form>
  5.  
  6. //Tombol Download
  7. <?php echo form_open('laporan/download_zip'); ?>
  8.    <div align="center">
  9.       <input type="submit" name="but_createzip2" class = "btn btn-primary" value="Download Zip" />
  10.    </div>
  11. <?php echo form_close(); ?>
  12. <!-- Disini saya tampilkan table list laporan berdasarkan Tahun -->
  13.  
  14. Controller
  15. public function index(){    
  16.         $tahun          = $this->input->post('tahun');
  17.         $data['lists']  = $this->laporan_model->list_laporan($tahun);
  18.          
  19.         $data['nama']   = $this->session->userdata('username');
  20.  
  21.         $this->load->view('templates/header',$data);
  22.         $this->load->view('laporan', $data);
  23.         $this->load->view('templates/footer');
  24. }
  25.  
  26. public function download_zip() {   
  27. // Read files from directory
  28. $tahun = $this->input->get('tahun');
  29. if($this->input-post('but_createzip2') != NULL){
  30. // File name
  31.     $filename = $tahun . _laporan.zip";
  32.     // Directory path (uploads directory stored in project root)
  33.     $path = './uploaded/laporan/'.$tahun.'/';
  34.    
  35.     // Add directory to zip
  36.     $this->zip->read_dir($path, FALSE);
  37.    
  38.     // Save the zip file to archivefiles directory
  39.     $this->zip->archive('./uploaded/backup_laporan/'. $filename);
  40.    
  41.     // Download
  42.     $this->zip->download($filename);
  43.     }
  44.    
  45.     // Load view
  46.     $this->load->view('v_detail_laporan');
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement