Skip to content

Instantly share code, notes, and snippets.

@azazqadir
Created August 18, 2017 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azazqadir/c4f535d40838f02713ab38515e4a0e7f to your computer and use it in GitHub Desktop.
Save azazqadir/c4f535d40838f02713ab38515e4a0e7f to your computer and use it in GitHub Desktop.
Controller for File Upload in CodeIgniter. Full tutorial here: https://www.cloudways.com/blog/codeigniter-upload-file-image/
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function custom_view(){
$this->load->view('custom_view', array('error' => ' ' ));
}
public function do_upload(){
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('custom_view', $error);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment