rondog Posted December 29, 2007 Share Posted December 29, 2007 I have a text area thats reading an xml file and I want to take whatever they change and save it back to the xml file. How would I got about doing that? My code looks like this so far and its displaying the xml in the text area. <?php $page = $_SERVER['PHP_SELF']; $filename = "gallery.xml"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); //echo $contents; $form = "<form action=\"$page\" method=\"get\">"; $form .= "<textarea name=\"\" cols=\"75\" rows=\"15\">$contents</textarea>"; $form .= "<input type=\"submit\" name=\"Submit\" value=\"Submit\" />"; $form .= "</form>"; echo $form; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83527-solved-save-data-back-to-xml-file/ Share on other sites More sharing options...
Daniel0 Posted December 29, 2007 Share Posted December 29, 2007 I don't see the problem. Just open the file for writing instead and then use fputs() instead of fread(). Quote Link to comment https://forums.phpfreaks.com/topic/83527-solved-save-data-back-to-xml-file/#findComment-424972 Share on other sites More sharing options...
rondog Posted December 29, 2007 Author Share Posted December 29, 2007 I dont know Im doing it wrong. Can you help me figure out what to do to write it. I have the file attributes set to 777. <?php $page = $_SERVER['PHP_SELF']; $submit = $_POST['Submit']; $newdata = $_POST['thexml']; $filename = "gallery.xml"; if($submit) { fwrite($filename,""); fwrite($filename, $newdata); } $handle = fopen($filename, "w"); $content = fread($handle, filesize($filename)); $form = "<form action=\"$page\" method=\"post\">"; $form .= "<textarea name=\"thexml\" cols=\"75\" rows=\"15\">$content</textarea>"; $form .= "<input type=\"submit\" name=\"Submit\" value=\"Submit\" />"; $form .= "</form>"; echo $form; ?> basically when they submit it clears whatever was in the xml file and then writes everything that was in the text area..I know its wrong but thats what im trying to achieve.. Quote Link to comment https://forums.phpfreaks.com/topic/83527-solved-save-data-back-to-xml-file/#findComment-424982 Share on other sites More sharing options...
Daniel0 Posted December 29, 2007 Share Posted December 29, 2007 Inside the first if you need to do $handle = fopen($filename, 'w'); fwrite($handle, $newdata); fclose($handle); Also, the fopen() you have in your code opens for writing, but you are attempting to read from it. If you use PHP5 you can use file_get_contents() and file_put_contents() instead. Quote Link to comment https://forums.phpfreaks.com/topic/83527-solved-save-data-back-to-xml-file/#findComment-424984 Share on other sites More sharing options...
rondog Posted December 31, 2007 Author Share Posted December 31, 2007 Ah cool man its working..one thing it added '\' before all quotation marks but I found stripslashes seemed to work..thanks Quote Link to comment https://forums.phpfreaks.com/topic/83527-solved-save-data-back-to-xml-file/#findComment-426783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.