Created
August 18, 2017 11:23
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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