Page 1 of 1

rename()

Posted: Thu Nov 23, 2006 7:30 pm
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");

Posted: Thu Nov 23, 2006 7:52 pm
by feyd
What was the error, specifically?

Posted: Thu Nov 23, 2006 7:54 pm
by Mute
No such file or directory

Posted: Fri Nov 24, 2006 1:35 am
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

Posted: Fri Nov 24, 2006 1:41 am
by John Cartwright
are you sure your php file and other source files are within the same directly?

Posted: Fri Nov 24, 2006 3:47 am
by onion2k
Why aren't you just writing the "data goes here" stuff straight into data.xml?