Welcome Guest, Not a member yet? Register   Sign In
rename function won't work inside foreach an while
#1

[eluser]jonny68[/eluser]
Hi,

as i upload images in a user folder i need to rename it

but i can't make it.

This is the code:

foreach($files as $file => $value){
$dir = './uploads/'.$this->session->userdata('username').'/';
$file = $files[$field_name]['name'];
rename($dir.$file,$dir.$field_name.$file);
}

It only renames correctly the last uploaded file in the array, the rest are left as they are and i get a php error, eventhough this is the right renamed file..

Message: rename(./uploads/Username/627239P.jpg,./uploads/Username/file_2627239P.jpg) [function.rename]: No such file or directory

THANK YOU IN ADVANCE!!
#2

[eluser]Zulkifli Said[/eluser]
i think your path is wrong.. try to review the path...

like this

Code:
rename('./imgs/content/'.$autorNome, './imgs/content/'.$this->input->post('nome'));
#3

[eluser]jonny68[/eluser]
Hi,

i just found out it wasn't about path,

this is a working foreach:

$dir = './uploads/'.$this->session->userdata('username').'/';
foreach($files as $file =>$value){
rename($dir.$value['name'],$dir.$file.$value['name']);
}

Thanks a lot anyway!




Theme © iAndrew 2016 - Forum software by © MyBB