Guest User

Untitled

a guest
Jun 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  1. <?php
  2.  
  3. class Upload extends Private_Controller {
  4.        
  5.         public function constructor() {
  6.                 parent::__constructor();
  7.         }
  8.        
  9.         function index() {
  10.            
  11.                 if ($this->ion_auth->logged_in()) {
  12.            
  13.                 $this->load->helper(array('form', 'url'));
  14.                 $this->load->library('form_validation');
  15.                
  16.                 $this->form_validation->set_rules('title', 'Title', 'required');
  17.                 $this->form_validation->set_rules('tags', 'Tag', 'required');
  18.                 $this->form_validation->set_rules('summary', 'Summary', 'required');
  19.                 $this->form_validation->set_rules('bookfile', 'Book File', 'required');
  20.                
  21.                 $this->load->view('topspace');
  22.                 if ($this->form_validation->run())
  23.                 {
  24.                         /*
  25.                             add file upload and conversion
  26.                             add tags to tag table
  27.                         */
  28.                        
  29.                        
  30.                         //Uploads cover file to server
  31.                         $coverconfig['upload_path'] = './uploads/coverimages';
  32.                         $coverconfig['allowed_types'] = 'jpg|png';
  33.                         $coverconfig['max_size']    = '500';
  34.                         $coverconfig['max_width']  = '5000';
  35.                         $coverconfig['max_height']  = '5000';
  36.                         $coverconfig['remove_spaces']  = 'TRUE';
  37.                        
  38.                         $this->load->library('upload', $coverconfig);
  39.                        
  40.                         $field_name = "coverimage";
  41.                        
  42.                         if ( ! $this->upload->do_upload($field_name))
  43.                         {
  44.                             $error = array('error' => $this->upload->display_errors());
  45.                
  46.                             $this->load->view('upload', $error);
  47.                         }
  48.                         else
  49.                         {
  50.                             $data = array('upload_data' => $this->upload->data());
  51.                
  52.                         }
  53.                        
  54.                         //Uploads book file to server
  55.                         $bookconfig['upload_path'] = './uploads/books_raw';
  56.                         $bookconfig['allowed_types'] = 'doc|pdf';
  57.                         $bookconfig['max_size'] = '1024';
  58.                         $bookconfig['remove_spaces']  = 'TRUE';
  59.                        
  60.                         $this->load->library('upload', $bookconfig);
  61.                        
  62.                         $bookfield_name = "bookfile";
  63.                        
  64.                         if ( ! $this->upload->do_upload($bookfield_name))
  65.                         {
  66.                             $error = array('error' => $this->upload->display_errors());
  67.                
  68.                             $this->load->view('upload', $error);
  69.                         }
  70.                         else
  71.                         {
  72.                             $data = array('upload_data' => $this->upload->data());
  73.                
  74.                             $this->load->view('upload_success');
  75.                         }
  76.                        
  77.                         //Puts info into databasees
  78.                         $title = $this->input->post('title');
  79.                         $tags = $this->input->post('tags');
  80.                         $summary = $this->input->post('summary');
  81.                        
  82.                         $user = $this->ion_auth->get_user();
  83.                         $authorid = $user->id;
  84.  
  85.                         $data = array(
  86.                             'book_title' => $title,
  87.                             'book_summary' => $summary,
  88.                             'book_author_id' => $authorid,
  89.                             'book_created' => time()
  90.                         );
  91.                         $this->db->insert('books', $data);
  92.                        
  93.                 }
  94.                 else
  95.                 {
  96.                         $this->load->view('upload');
  97.                 }
  98.                 $this->load->view('footer');
  99.                
  100.                 } else {
  101.                     $this->load->view('mustlogin');
  102.                 }
  103.                
  104.                
  105.                
  106.         }
  107.        
  108. }
Add Comment
Please, Sign In to add comment