• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
upload question

#1
[eluser]kris10[/eluser]
Hello

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

#2
[eluser]Twisted1919[/eluser]
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:
Code:
Array
(
    [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 .


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.