myitalan Posted July 14, 2012 Share Posted July 14, 2012 Greetings, Thank you for your posts... it's been very helpful. I have an issue i hope you can help me with regarding parsing an xml file to table in php. 1. I have an input form that writes an xml file. (it works) 2. the xml file it writes is in this format: <?xml version="1.0" encoding="iso-8859-1"?> <images> <title>2</title> <description>2</description> <tmg></tmg> <img>2</img> </images> 3. Now, this is what I need for my flash gallery to play and I can't change that. 4. The Problem is when I list all the images in the admin section to add and delete, I am getting a parsing error. - Clue the parser will work if I format the xml file like this: <images> <image title="2" description="2" tmb="2" img="2" /> </images> 5. Finally, yes I would write to that format using: $write_string = "<images>"; foreach($images_final as $image){ $write_string .= "<image title=\"$image[title]\" description=\"$image[description]\" tmb=\"$image[tmb]\" img=\"$image[img]\" />"; } $write_string .= "</images>"; $fp = fopen("gallery.xml", "w+"); fwrite($fp, $write_string) or die("Error writing to file"); fclose($fp); ....but my flash gallery won't work. Here is what I'm using that is generating the error. <?php function start_tag($parser, $name, $attrs){ global $table_string; $table_string .= "<tr><td>[title]</td><td>[description]</td><td>[tmb]</td><td>[img]</td></tr>"; } function end_tag($parser, $name){} $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($parser, "start_tag", "end_tag"); $table_string = "<table> <tr><th>Title</th><th>Description</th><th>Thumbnail</th><th>Image</th></tr>"; xml_parse($parser, file_get_contents("gallery.xml")) or die("Error parsing XML file"); $table_string .= "</table>"; echo $table_string; ?> Thank you in advance for your help!! Alan Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/ Share on other sites More sharing options...
xyph Posted July 14, 2012 Share Posted July 14, 2012 What kind of error? It seems to parse fine for me <?php $data = '<?xml version="1.0" encoding="iso-8859-1"?> <images> <title>2</title> <description>2</description> <tmg></tmg> <img>2</img> </images>'; $xml = new SimpleXMLElement($data); print_r($xml); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361558 Share on other sites More sharing options...
myitalan Posted July 15, 2012 Author Share Posted July 15, 2012 Thank you for your reply. I thought no one was going to reply so I went in another direction. However I would appreciate if you take a look at my new road block. I am still editing an xml file.. uploading images and updating the xml file. Here is my error followed by the code. Notice: Undefined variable: _FILES2 in /playlistaction.php on line 16 Notice: Undefined variable: _FILES2 in /playlistaction.php on line 17 Notice: Undefined variable: _FILES2 in /playlistaction.php on line 18 Notice: Undefined variable: _FILES2 in /playlistaction.php on line 19 Warning: Wrong parameter count for move_uploaded_file() in /playlistaction.php on line 22 Error uploading file ------------------------------- <?php ini_set('display_errors',1); error_reporting(-1); $uploadDir = 'photoGallery/'; $uploadDir2 = 'photoGallery/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $fileName2 = $_FILES2['userfile2']['name2']; $tmpName2 = $_FILES2['userfile2']['tmp_name2']; $fileSize2 = $_FILES2['userfile2']['size2']; $fileType2 = $_FILES2['userfile2']['type2']; $filePath2 = $uploadDir2 . $fileName2; $result = move_uploaded_file($tmpName, $tmpName2, $filePath, $filePath2); if (!$result) { echo "Error uploading file"; exit; } } $song = array( 'title' => $_POST['title'], 'description' => $_POST['description'], 'tmb' => $filePath, 'img' => $filePath2, ); $doc = new DOMDocument(); $doc->load( 'photoGallery.xml' ); $doc->formatOutput = true; $r = $doc->getElementsByTagName("musiclist")->item(0); $b = $doc->createElement("song"); $title = $doc->createElement("title"); $title->appendChild( $doc->createTextNode( $song["title"] ) ); $b->appendChild( $title ); $description = $doc->createElement("description"); $description->appendChild( $doc->createTextNode( $song["description"] ) ); $b->appendChild( $description ); $tmb = $doc->createElement("tmb"); $tmb->appendChild( $doc->createTextNode( $song["tmb"] ) ); $img = $doc->createElement("img"); $img->appendChild( $doc->createTextNode( $song["img"] ) ); $b->appendChild( $tmb ); $b->appendChild( $img ); $r->appendChild( $b ); $doc->save("photoGallery.xml"); header("Location: {$_SERVER['HTTP_REFERER']}"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361578 Share on other sites More sharing options...
xyph Posted July 15, 2012 Share Posted July 15, 2012 It's pretty self-explanatory. Have you checked the lines the error report mentions? Have you read this? http://php.net/manual/en/features.file-upload.php Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361580 Share on other sites More sharing options...
myitalan Posted July 15, 2012 Author Share Posted July 15, 2012 Again Thx, It works when I upload only one image. When adding $uploadDir2 = 'photoGallery/'; and $fileName2 is when I'm getting stuck. I'm sure I'm not writing the code right. Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361581 Share on other sites More sharing options...
xyph Posted July 15, 2012 Share Posted July 15, 2012 Here's a hint, $_FILES2 won't exist unless you create it. PHP only creates a $_FILES superglobal array for you Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361582 Share on other sites More sharing options...
myitalan Posted July 15, 2012 Author Share Posted July 15, 2012 updated based on your hint, and suggestion. No errors!!!! but no action???? no entries added <?php ini_set('display_errors',1); error_reporting(-1); $uploadDir = 'photoGallery/'; $uploadDir2 = 'photoGallery/'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $fileName2 = $_FILES['userfile2']['name']; $tmpName2 = $_FILES['userfile2']['tmp_name']; $fileSize2 = $_FILES['userfile2']['size']; $fileType2 = $_FILES['userfile2']['type']; $filePath2 = $uploadDir2 . $fileName2; $result = move_uploaded_file($tmpName, $filePath,); if (!$result) { echo "Error uploading file"; exit; } } $song = array( 'title' => $_POST['title'], 'description' => $_POST['description'], 'tmb' => $filePath, 'img' => $filePath2, ); $doc = new DOMDocument(); $doc->load( 'photoGallery.xml' ); $doc->formatOutput = true; $r = $doc->getElementsByTagName("musiclist")->item(0); $b = $doc->createElement("song"); $title = $doc->createElement("title"); $title->appendChild( $doc->createTextNode( $song["title"] ) ); $b->appendChild( $title ); $description = $doc->createElement("description"); $description->appendChild( $doc->createTextNode( $song["description"] ) ); $b->appendChild( $description ); $tmb = $doc->createElement("tmb"); $tmb->appendChild( $doc->createTextNode( $song["tmb"] ) ); $img = $doc->createElement("img"); $img->appendChild( $doc->createTextNode( $song["img"] ) ); $b->appendChild( $tmb ); $b->appendChild( $img ); $r->appendChild( $b ); $doc->save("photoGallery.xml"); header("Location: {$_SERVER['HTTP_REFERER']}"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361587 Share on other sites More sharing options...
xyph Posted July 15, 2012 Share Posted July 15, 2012 You aren't doing anything with $tmpName2, or any of the other variables that end in 2 Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361589 Share on other sites More sharing options...
myitalan Posted July 15, 2012 Author Share Posted July 15, 2012 Things that used to work isn't, so i had to rebuild to this point. I am stuck... don't know if the second image should be included with the first group of code or if it should be separate being that it's no errors just a blank screen i don't know what to do. Would you mind a little push? Thx Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361594 Share on other sites More sharing options...
xyph Posted July 15, 2012 Share Posted July 15, 2012 As opposed to what I've already been giving you? Is it safe to assume you don't really understand the code you've posted? Be honest here Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361596 Share on other sites More sharing options...
myitalan Posted July 15, 2012 Author Share Posted July 15, 2012 Ohhh by far am I not afraid to admit my ignorance with coding. I can make minor edits to php but in no way skilled. I do respect your craft as why I don't just ask for you to give it to me as it is better for me in the long run and by the time of my first post and now should show that I'm not afraid to put in the time just to get one function working. I've been at it for 9+ hours and just asking for a push as I am truly stuck. At this point I'd just be messing up what I got... I made changes from your hint, but now I'm wondering if i actually made the right changes.... What is right about my code and should leave alone and what wrong. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361600 Share on other sites More sharing options...
myitalan Posted July 15, 2012 Author Share Posted July 15, 2012 Thanks xyph for your help! If you've gone as far as you can with me... Please reply so I can move in another direction as this apparently is fullstop for me. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361610 Share on other sites More sharing options...
xyph Posted July 15, 2012 Share Posted July 15, 2012 I'm a volunteer. I can't be here 24/7 waiting for replies from you Other stuff going on. If you'd like, I'm more than happy to help you do this right... by that I mean start from scratch and make sure you understand what each line is doing. If you just need it done ASAP, I suggest going over to the freelance forum, and perhaps requesting the user explains the code as well, if you have the extra money. What you're asking isn't help, it's pretty much standing behind you while you blindly make changes to the code. I'd much rather take the time to help you learn PHP. Quote Link to comment https://forums.phpfreaks.com/topic/265679-xml-to-php-table/#findComment-1361695 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.