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
Mute
Forum Newbie
Posts: 15 Joined: Mon Jul 10, 2006 9:02 am
Post
by Mute » Thu Nov 23, 2006 7:30 pm
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");
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Nov 23, 2006 7:52 pm
What was the error, specifically?
Mute
Forum Newbie
Posts: 15 Joined: Mon Jul 10, 2006 9:02 am
Post
by Mute » Thu Nov 23, 2006 7:54 pm
No such file or directory
dibyendrah
Forum Contributor
Posts: 491 Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:
Post
by dibyendrah » Fri Nov 24, 2006 1:35 am
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 :
Regards,
Dibyendra
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Nov 24, 2006 1:41 am
are you sure your php file and other source files are within the same directly?
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Fri Nov 24, 2006 3:47 am
Why aren't you just writing the "data goes here" stuff straight into data.xml?