CodeIgniter Forums
upload question - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: upload question (/thread-36730.html)

upload question - El Forum - 12-13-2010


Writing an application with music file, I write the upload code

But what I would like to to is rename the file by the id of the record but keep the extension.

I already rename by 1.mp3 or id but I can I have other extension

I don't know how to check the extension it could be mp3 ogg or wma ...

Quote:$config['file_name'] = $_POST['id'].".mp3";

how to replace ".mp3" but the right code in order to keep the orgininal ext of the file and just rename the name of the file

upload question - El Forum - 12-13-2010

Ain't gonna work like this .
First, you need to upload the file as it is, then, you get the properties of the uploaded file like
$props = $this->upload->data();
now, $props is an array, containing:
    [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
    [client_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"

Knowing that, you can use rename() to move rename your file to other name, but keep the extension .