Page 1 of 1

rename a file using PHP

Posted: Sat Jun 21, 2008 3:48 am
by vb_123
hello friends,
How can i rename a file(text or jpg file) which is placed inside a folder using php??????does anybody have a code for this

Re: rename a file using PHP

Posted: Sat Jun 21, 2008 3:54 am
by calcop
Here you go:

Code: Select all

 
rename($oldfilename, $newfilename);
 
or

Code: Select all

 
exec("mv $oldfilename $newfilename");
 
- matt

Re: rename a file using PHP

Posted: Sat Jun 21, 2008 3:56 am
by Kieran Huggins

Re: rename a file using PHP

Posted: Sat Jun 21, 2008 4:14 am
by vb_123
i have to make it using a function and not just have to use "rename" function.i have to make a function like this

function rename($dirpath,$oldfilename,$newfilename)

and this function must be recursive and a directory can contain subdirectory also

Re: rename a file using PHP

Posted: Sat Jun 21, 2008 4:16 am
by Kieran Huggins