Welcome Guest, Not a member yet? Register   Sign In
How to Display Upload Errors
#3

[eluser]RMinor[/eluser]
After I did that my page and testimonial variables are undefined. Here is my new controller...

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Upload extends CI_Controller {

protected $_page = 'upload';

public function __construct()
{
  parent::__construct();
}

public function index()
{
  $this->load->model('Upload_model');
  $data['page'] = $this->Global_model->pageInformation($this->_page);
  $data['testimonials'] = $this->Upload_model->getTestimonials();
  $this->load->helper('form');  
  $this->load->library('form_validation');
  $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  $this->form_validation->set_rules('name', 'Name', 'trim|required');
  $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
  $this->form_validation->set_rules('birth_month', 'Birth Month', 'trim|required|integer|exact_length[2]');
  $this->form_validation->set_rules('birth_day', 'Birth Day', 'trim|required|integer|exact_length[2]');
  $this->form_validation->set_rules('birth_year', 'Birth Year', 'trim|required|integer|exact_length[4]');
  $this->form_validation->set_rules('ip', 'IP Adress', 'trim|required|valid_ip');
  if($this->form_validation->run() == FALSE) {} else {
   if ($data = $this->process_upload()) {
    redirect('upload_success');
   }
  }
  $this->load->view('upload_view', $data);
}

/**
  * Method to upload two images and create thumbnails of them.
  */
public function process_upload()
{
  $data['error']=NULL;
  $this->load->library('upload');
  $this->load->library('image_lib');
  $config['upload_path'] = './models/';
  $config['allowed_types'] = 'gif|jpg|jpeg|png';
  $config['max_size'] = '2048';
  $config_thumb['create_thumb'] = TRUE;
  $config_thumb['maintain_ratio'] = TRUE;
  $config_thumb['width'] = 150;
  $config_thumb['height'] = 150;
  if (!empty($_FILES['photo_one']['name'])) {
   $this->upload->initialize($config);
   if (!$this->upload->do_upload('photo_one')) {
    $data['error'][] = $this->upload->display_errors();    
    return FALSE;              
            } else {
    $photo_info = $this->upload->data();
    $config_thumb['source_image'] = $photo_info['full_path'];
    $db_info['photo_one'] = $photo_info['file_name'];
    $this->image_lib->initialize($config_thumb);
    $this->image_lib->resize();
    $db_info['thumb_one'] = $photo_info['raw_name'] . '_thumb' . $photo_info['file_ext'];
    $this->image_lib->clear();
   }
  }
  if (!empty($_FILES['photo_two']['name'])) {
   $this->upload->initialize($config);
   if (!$this->upload->do_upload('photo_two')) {
    $data['error'][] = $this->upload->display_errors();
    return FALSE;              
   } else {
    $photo_info = $this->upload->data();
    $config_thumb['source_image'] = $photo_info['full_path'];
    $db_info['photo_two'] = $photo_info['file_name'];
    $this->image_lib->initialize($config_thumb);
    $this->image_lib->resize();
    $this->image_lib->clear();
    $db_info['thumb_two'] = $photo_info['raw_name'] . '_thumb' . $photo_info['file_ext'];
   }
  }
  $this->Upload_model->addModel($db_info);
  return $data;
}

}


Messages In This Thread
How to Display Upload Errors - by El Forum - 02-17-2012, 08:48 AM
How to Display Upload Errors - by El Forum - 02-17-2012, 09:08 AM
How to Display Upload Errors - by El Forum - 02-17-2012, 11:20 AM
How to Display Upload Errors - by El Forum - 02-18-2012, 08:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB