// Step 1: Load the necessary library
$this->load->library('upload');
// Step 2: Set up the upload configuration
$config['upload_path'] = 'your/upload/path/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000; // Set the maximum file size in kilobytes
// Step 3: Initialize the upload library with the configuration
$this->upload->initialize($config);
// Step 4: Specify the new file name
$new_file_name = 'your_new_file_name.ext'; // Change 'your_new_file_name' to your desired file name (without extension)
// Step 5: Get the original file name
$original_file_name = $_FILES['userfile']['name'];
// Step 6: Extract file extension from the original file name
$file_ext = pathinfo($original_file_name, PATHINFO_EXTENSION);
// Step 7: Set the new file name with the original extension
$config['file_name'] = $new_file_name . '.' . $file_ext;
// Step 8: Update the upload configuration with the new file name
$this->upload->initialize($config);
// Step 9: Perform the file upload
if ($this->upload->do_upload('userfile')) {
// File uploaded successfully, you can perform further actions if needed
} else {
// File upload failed, handle the error
$error = $this->upload->display_errors();
// Add your error handling logic here
}