rename a file using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vb_123
Forum Newbie
Posts: 19
Joined: Wed May 21, 2008 2:16 am

rename a file using PHP

Post 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
calcop
Forum Newbie
Posts: 20
Joined: Fri Mar 04, 2005 2:13 pm

Re: rename a file using PHP

Post by calcop »

Here you go:

Code: Select all

 
rename($oldfilename, $newfilename);
 
or

Code: Select all

 
exec("mv $oldfilename $newfilename");
 
- matt
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: rename a file using PHP

Post by Kieran Huggins »

vb_123
Forum Newbie
Posts: 19
Joined: Wed May 21, 2008 2:16 am

Re: rename a file using PHP

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: rename a file using PHP

Post by Kieran Huggins »

Post Reply