Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Upload extends Private_Controller {
- public function constructor() {
- parent::__constructor();
- }
- function index() {
- if ($this->ion_auth->logged_in()) {
- $this->load->helper(array('form', 'url'));
- $this->load->library('form_validation');
- $this->form_validation->set_rules('title', 'Title', 'required');
- $this->form_validation->set_rules('tags', 'Tag', 'required');
- $this->form_validation->set_rules('summary', 'Summary', 'required');
- $this->form_validation->set_rules('bookfile', 'Book File', 'required');
- $this->load->view('topspace');
- if ($this->form_validation->run())
- {
- /*
- add file upload and conversion
- add tags to tag table
- */
- //Uploads cover file to server
- $coverconfig['upload_path'] = './uploads/coverimages';
- $coverconfig['allowed_types'] = 'jpg|png';
- $coverconfig['max_size'] = '500';
- $coverconfig['max_width'] = '5000';
- $coverconfig['max_height'] = '5000';
- $coverconfig['remove_spaces'] = 'TRUE';
- $this->load->library('upload', $coverconfig);
- $field_name = "coverimage";
- if ( ! $this->upload->do_upload($field_name))
- {
- $error = array('error' => $this->upload->display_errors());
- $this->load->view('upload', $error);
- }
- else
- {
- $data = array('upload_data' => $this->upload->data());
- }
- //Uploads book file to server
- $bookconfig['upload_path'] = './uploads/books_raw';
- $bookconfig['allowed_types'] = 'doc|pdf';
- $bookconfig['max_size'] = '1024';
- $bookconfig['remove_spaces'] = 'TRUE';
- $this->load->library('upload', $bookconfig);
- $bookfield_name = "bookfile";
- if ( ! $this->upload->do_upload($bookfield_name))
- {
- $error = array('error' => $this->upload->display_errors());
- $this->load->view('upload', $error);
- }
- else
- {
- $data = array('upload_data' => $this->upload->data());
- $this->load->view('upload_success');
- }
- //Puts info into databasees
- $title = $this->input->post('title');
- $tags = $this->input->post('tags');
- $summary = $this->input->post('summary');
- $user = $this->ion_auth->get_user();
- $authorid = $user->id;
- $data = array(
- 'book_title' => $title,
- 'book_summary' => $summary,
- 'book_author_id' => $authorid,
- 'book_created' => time()
- );
- $this->db->insert('books', $data);
- }
- else
- {
- $this->load->view('upload');
- }
- $this->load->view('footer');
- } else {
- $this->load->view('mustlogin');
- }
- }
- }
Add Comment
Please, Sign In to add comment