PDA

View Full Version : HELP! Using PHP, Flash and XML to rewrite file



dezamp
November 11th, 2006, 05:32 AM
<?php
$file = fopen("user.xml", "w+") or die("Can't open XML file");
$xmlString = $HTTP_RAW_POST_DATA;
if(!fwrite($file, $xmlString)){
print "Error writing to XML-file";
}
print $xmlString."\n";
fclose($file);
?>I have this code currently from a Kirupa tutorial but this only adds to the xml file. I want it so that it will completely rewrite the xml. Please help!

Zaid_W1red
November 11th, 2006, 06:52 AM
the easiest thing to do would be delete the xml file before writing it.

This means the file is created from scratch.



unlink('user.xml')


....that at the top of your PHP should do the trick.

dezamp
November 11th, 2006, 11:29 AM
the easiest thing to do would be delete the xml file before writing it.

This means the file is created from scratch.



unlink('user.xml')
....that at the top of your PHP should do the trick.

Could you possibly give me the whole bit of code because i'm not entirely sure where to put it or what to get rid of! (I don't know php)

Zaid_W1red
November 11th, 2006, 12:38 PM
er...did you read my post?

The code is there and I even told you where to put it?!

hl
November 11th, 2006, 01:25 PM
Uh, why would you delete the file? That's just another step.

Besides, your current code should be rewriting the file entirely. [d-php]fopen[/d-php]

The use of w+ should be eating the file for your to put in your new contents as it is.. try changing w+ to just w. It might be expecting to be read before trunucating it. I've never experimented with that.

Zaid_W1red
November 11th, 2006, 01:31 PM
hl is correct ..I was just offering a quick solution to an inexpierienced PHP'er.

hl
November 11th, 2006, 01:46 PM
Don't give bad experience to those who lack experience period ;) It's always good to teach the efficient methods early on. Plus, the modes of fopen are well documented.

Zaid_W1red
November 11th, 2006, 02:18 PM
point taken ;)