rename()

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
Mute
Forum Newbie
Posts: 15
Joined: Mon Jul 10, 2006 9:02 am

rename()

Post by Mute »

Hi,

I'm trying to rename a temporary file I've created but it doesn't work. Says the file doesn't exist. When I do a file_exists() on the file, it also says it doesn't exist. Yet I can see the file on the server....

Any ideas?

Code: Select all

//create temp file
$tmp = time().".xml";
$handle = fopen($tmp, "w");
fwrite($handle, "data goes here");
fclose($handle);

//rename temp file
rename($tmp, "data.xml");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What was the error, specifically?
Mute
Forum Newbie
Posts: 15
Joined: Mon Jul 10, 2006 9:02 am

Post by Mute »

No such file or directory
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

It works and contains no error.

Code: Select all

<?php
$tmp = time().".xml";
$handle = fopen($tmp, "w");
fwrite($handle, "data goes here");
fclose($handle);

//rename temp file
rename($tmp, "data.xml"); 

if(file_exists("data.xml")){
	print "File Exists";
}

?>
Output :

Code: Select all

File Exists
Regards,
Dibyendra
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

are you sure your php file and other source files are within the same directly?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Why aren't you just writing the "data goes here" stuff straight into data.xml?
Post Reply