PHP rename error
I get this error when using the rename function
Warning: rename(../data/feeds/feed2.txt,../data/feeds/feed3.txt) [function.rename]: No error in C:\wamp\www\cms\admin\pages\feeds.php on line 32
"../data开发者_JAVA技巧/feeds/feed2.txt" is the correct path, I have done include("../data/feeds/feed2.txt") and it displays the file. And "../data/feeds/feed3.txt" doesn't exist.
Anyone know what's causing this?
you should check if "../data/feeds/feed2.txt" is readable and if "../data/feeds/feed3.txt" is writable...
$oldname = '';
$newname = '';
if (
file_exists($oldname)&&
(
(!file_exists($newname))||
is_writable($newname)
)
) {
rename($oldname, $newname);
}
Did you enclose strings in quotes?
rename('../data/feeds/feed2.txt','../data/feeds/feed3.txt');
You can use in try-catch statements : copy( $old_name, $new_name ); unlink($old_name);
Just you must be sure that directory is writable.
In your case u must be sure that this destination file is exists or use absolute file paths
精彩评论