ItSolutionStuff.com

Codeigniter Get File Extension Before Upload Example

By Hardik Savani • November 5, 2023
Codeigniter

Are you looking for codeigniter get extension of file before upload then i will help you to get file extension in codeigniter from file name. we can get file extension using pathinfo() php function.

I was new to codeigniter application. i was using codeigniter 3 version. i was doing image upload task on my project and i need to make custom name of image when you upload on my server. At that time need to get image file extension from name and then i will rename it form extension. i search a lot about to getting directly for file extension but it was not there in codeigniter docs. i thought and find way to do it using php pathinfo().

I created simple example for getting file extension in codeigniter project. so you can see both example, i hope it can help you.

Example 1:

$fileExt = pathinfo($_FILES["image"]["name"], PATHINFO_EXTENSION);

print_r($fileExt);

Example 2:

$fileName = $this->upload->data('image');

$fileExt = pathinfo($fileName, PATHINFO_EXTENSION);

print_r($fileExt);

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Current Month Records in Codeigniter?

Read Now →

Codeigniter Form Validation with Error Message

Read Now →

Codeigniter Add/Remove Multiple Input Fields Dynamically using JQuery

Read Now →

Codeigniter Compress Image Size Example

Read Now →

How to Create a Custom Library in CodeIgniter?

Read Now →

How to Get Last Executed Query in Codeigniter?

Read Now →

Codeigniter Dynamic Highcharts Example

Read Now →

Codeigniter Google Recaptcha Form Validation Example

Read Now →

Codeigniter Ajax Pagination using JQuery Example

Read Now →

Codeigniter JQuery Ajax Request Example

Read Now →

Codeigniter Confirm Box Before Delete Record Example

Read Now →

Codeigniter Multiple Database Connection Example

Read Now →

Codeigniter Ajax CRUD Tutorial Example

Read Now →

How to Get Current URL with Query String in Codeigniter?

Read Now →