How to rename file on upload in codeigniter?

Today, We want to share with you rename file upload codeigniter.In this post we will show you Renaming an uploaded file in CodeIgniter, hear for codeigniter get filename before upload we will give you demo and example for implement.In this post, we will learn about Laravel Renaming Uploaded Files Automatically with an example.

Dynamically Codeigniter Image Upload Rename

Step 1.

Create a codeigniter” controller for “Rename a file while uploading in codeigniter”.

Example 1: Change controller
Use below in your own controller.

class Test extends CI_Controller {

	public function index()
		$this->load->library('upload', $config); 
			$image = time().'-'.$_FILES["image"]['name']; //Filename
			$config = array(
						'upload_path' => "./uploads/",   //here folder name added Upload file Destination 
						'allowed_types' => "gif|jpg|png|jpeg|JPEG|JPG|PNG|GIF",  //some added Accepted types
						'overwrite' => TRUE,
						'max_size' => "1024",    //here set your Maximum upload file size
						'max_height' => "985",
						'max_width' => "1600",
						'file_name' => $image
				$result['msg']="Good Luck, File uploaded successfully!";
			} else {
				$result['msg']="Sorry, Error in upload file.";
			$this->load->view('image', $result);

encrypt file name with use of CI native option:

$config['encrypt_name'] = TRUE;

your own source code:

Also Read This 👉   CodeIgniter Enable Disable debug mode

$new_name = time().$_FILES["userfiles"]['name'];
$config['file_name'] = $new_name;

I hope you get an idea about Rename file upload codeigniter.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.