Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Rename file when uploading it?
#1

[eluser]chefnelone[/eluser]
Hello

I'm using this code for uploading files. Works fine, but I'like to lowercase the file name before uploading the file.
Let's say the file name is: My_File.JPG change to my_file.jpg (note that I need to lowercase the extension too)
How should I do that?

Code:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '3000';
$config['max_width']  = '1200';
$config['max_height']  = '1200';


//I thought something like: strtolower()but don't know how to get the name of the file;

$this->load->library('upload', $config);
$this->upload->do_upload();
#2

[eluser]danmontgomery[/eluser]
Code:
$data = $this->upload->data();
rename($data['full_path'], $data['file_path'] . strtolower($data['file_name']));
#3

[eluser]chefnelone[/eluser]
[quote author="noctrum" date="1269463250"]
Code:
$data = $this->upload->data();
rename($data['full_path'], $data['file_path'] . strtolower($data['file_name']));
[/quote]

Thanks noctrum,
For what you say I understand that I can't rename the file before uploading it? Then I need to rename once it's uploaded.
Am I right?
#4

[eluser]gvillavizar[/eluser]
[quote author="chefnelone" date="1269463590"][quote author="noctrum" date="1269463250"]
Code:
$data = $this->upload->data();
rename($data['full_path'], $data['file_path'] . strtolower($data['file_name']));
[/quote]

Thanks noctrum,
For what you say I understand that I can't rename the file before uploading it? Then I need to rename once it's uploaded.
Am I right?[/quote]

Exactly! Smile
#5

[eluser]chefnelone[/eluser]
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB