CodeIgniter Integration

See all posts Reply

CodeIgniter Integration new!
by Konstsntin, 13 years, 11 months ago
Hi,
CodeIgniter's native upload library doesn't allow to manipulate images as it is necessary. I have tried to connect a class to CodeIgniter, but have come to grief :-( Whether there is at somebody an experience of such integration?
1) I have remaned class.upload.php to My_upload.php and copied it into application/librires folder
2) try:
function __construct() {
  parent::__construct();
  $this->load->helper(array('form', 'url'));
  $this->load->library('my_upload');
}
function do_upload() {
  $now = date("YmdHis");
  $config['upload_path'] = './uploads/userpics/tmp/';
  $uploaded = $this->my_upload->upload($_FILES["userfile"]);
  if ( $uploaded ) {
    $this->my_upload->file_new_name_body   = 'image_resized' . $now;
    $this->my_upload->image_resize         = true;
    $this->my_upload->image_x              = 100;
    $this->my_upload->image_ratio_y        = true;
    $this->my_upload->process('./uploads/userpics/');
    if ( $this->my_upload->processed() ) {
      echo "OK";
      $this->my_upload->clean();  
    } else {
      echo "ERROR";
    }
  } 
  else echo "ERROR";    
}
But have only errors...Reply
First solution: CodeIgniter Integration new!
by Konstantin, 13 years, 11 months ago
Hi, that my first solution:
class Upload extends CI_Controller {
  
  function __construct() {
    parent::__construct();
    $this->load->helper(array('form', 'url'));
    $this->load->library('my_upload');
  }
  
  function index() { 
    $data['page'] = 'upload_form';
    $data['errors'] = '';
    $data['title'] = 'Upload From';
    $this->load->view('container',$data);
  }

  function do_upload() {
    $now = date("YmdHis");
    $this->my_upload->upload($_FILES["userfile"]);
    if ( $this->my_upload->uploaded == true  ) {
      $this->my_upload->allowed         = array('image/*');
      $this->my_upload->file_new_name_body    = 'image_resized' . $now;
      $this->my_upload->image_resize          = true;
      $this->my_upload->image_x               = 100;
      $this->my_upload->image_ratio_y         = true;
      $this->my_upload->process('./uploads/userpics/');
      if ( $this->my_upload->processed == true ) {
        $data['page'] = 'upload_success';
        $this->load->view('container',$data);
        $this->my_upload->clean();  
      } else {
        $data['errors'] = $this->my_upload->error;
        $data['page'] = 'upload_form';
        $this->load->view('container',$data);
      }
    } else  {
      $data['errors'] = $this->my_upload->error;
      $data['page'] = 'upload_form';
      $this->load->view('container',$data); 
    }
  } 
}
Work fine, thaks for your work :-)Reply
Re: First solution: CodeIgniter Integration new!
by Gabriel, 11 years ago
Works bealtifull! Tanks man! You save my life!Reply
Re: First solution: CodeIgniter Integration new!
by Javid Abbasov, 7 years, 9 months ago
Hi. I have tried this code in Codeigniter 3.1.6 however it says https://yadi.sk/i/ad0OmxLT3NhhJZ . Here is library name https://yadi.sk/i/E7Lxf6D_3NhhML . And here is my controller: https://pastebin.com/x2iXKA14Reply
Re: CodeIgniter Integration new!
by colin, 13 years, 11 months ago
You can also check out this thread on the CodeIgniter forumsReply
CodeIgniter Integration new!
by Konstantin, 13 years, 11 months ago
Colin, thanks a lot. I try to learn to work in CI. Some days suffered with an original class. Your class has connected for two hours :-)Reply