how to use rename() function?

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
geniussadi
Forum Newbie
Posts: 3
Joined: Thu May 06, 2010 4:19 pm

how to use rename() function?

Post by geniussadi »

I have a lot of experience working with PHP, but I'm unable to make rename() working for me.

I'm getting this error.
Warning: rename(c:/zerocall_cdr/Cdr_1282293451.csv,c:/zerocall_cdr/error/Cdr_1282293451.csv) [function.rename]: No such file or directory in .... .php on line 162
And this is the code,

Code: Select all

$root_dir = 'c:/zerocall_cdr';
$backup_dir = $root_dir.'/backup';

$file = "Cdr_1282293451.csv";

rename("$root_dir/$file", "$backup_dir/$file");
Let me know what I'm doing wrong in it?
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: how to use rename() function?

Post by amargharat »

The error you are getting is about no existence of directory or file.
So, make sure about directory exists or not.

In your code, u r renaming from root to root/backup

but in u r error, destination path contains root/error/filename.

So, that causes the error
Post Reply