PHP creating or over writing a file

Associate
Joined
27 Jun 2006
Posts
1,473
Afternoon all :)

I have a script, that when run from the browser creates an XML file.
If the file isn't there the script creates the file.
If the file is already there the script should overwrite the contents.

The line I have to try to do this is:

PHP:
$xmlfile = "graphs/".$server.".xml";
$fh = fopen($xmlfile, 'x+') or die("Cannot open $xmlfile!");

It works fine when there is no file already there, but if its present I get the error:

Code:
Warning: fopen(graphs/123.123.123.123.xml) [function.fopen]: failed to open stream: File exists in ........

123.123.123.123 is an IP address.

Any help to get the script to create or overwrite appreciated....I thought it would be so easy!!

M.
 
Back
Top Bottom