Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codeigniter - Rename file while upload
<?php
/*
Author: Mukesh Jakhar
Description: Rename file while uploading in codeigniter (Controller)
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Image extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
if($this->input->post('uploadImage'))
{
$image = time().'-'.$_FILES["image"]['name'];
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|JPEG|JPG|PNG|GIF",
'overwrite' => TRUE,
'max_size' => "99999999999",
'max_height' => "800",
'max_width' => "1500",
'file_name' => $image
);
$this->load->library('upload', $config);
if($this->upload->do_upload('image'))
{
$res['msg']="Image has been uploaded!";
$this->load->view('image', $res);
}
else
{
$this->load->view('image');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment