CodeIgniter Forums

Full Version: [solved] get latest file name after uploading file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi, everyone..

i have a bit question, i'm just try to upload image using file uploading class,
and it works perfectly.

but now i have no idea how to get the latest file_name after auto renaming files.


1. upload ci.jpg
2. upload ci.jpg again then its automatically numbered, so become ci1.jpg

my question is how to get the name ci1.jpg so i can put it on database.


El Forum

Check out the File Uploading Class

This is a helper function that returns an array containing all of the data related to the file you uploaded. Here is the array prototype:

[file_name] => mypic.jpg
[file_type] => image/jpeg
[file_path] => /path/to/your/upload/
[full_path] => /path/to/your/upload/jpg.jpg
[raw_name] => mypic
[orig_name] => mypic.jpg
[file_ext] => .jpg
[file_size] => 22.2
[is_image] => 1
[image_width] => 800
[image_height] => 600
[image_type] => jpeg
[image_size_str] => width="800" height="200"

Here is an explanation of the above array items.

Item Description
file_name The name of the file that was uploaded including the file extension.
file_type The file's Mime type
file_path The absolute server path to the file
full_path The absolute server path including the file name
raw_name The file name without the extension
orig_name The original file name. This is only useful if you use the encrypted name option.
file_ext The file extension with period
file_size The file size in kilobytes
is_image Whether the file is an image or not. 1 = image. 0 = not.
image_width Image width.
image_heigth Image height
image_type Image type. Typically the file extension without the period.
image_size_str A string containing the width and height. Useful to put into an image tag.

Orig_name being the original name, as otherwise (such as in the path) you get the new name.

El Forum

thanks for your reply,

is it any query maybe something like these :


sorry i'm still newbie here..

El Forum


$data = $this->upload->data();
echo $data['file_name'];

upload->data() returns an array with all that info in it. You can use var_dump($data) with the above code to get a better feel for all the information the file upload class returns.

El Forum

Thanks Brian, it's solved now :-)