Matrix015 Posted June 8, 2011 Share Posted June 8, 2011 Hey all, I know next to nothing about coding in PHP. I found this script that allows me to read the contents of a directory and transform it into XML format. I was wondering if there was a way to have it read two different file types. Eg. Right now it reads all the files and puts their path into the <image> tag. I would like to be able to read a text file and put it into a description. All of this ends up in a Flash Presentation. $path_to_image_dir = 'images'; // relative path to your image directory $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <images> </images> XML; $xml_generator = new SimpleXMLElement($xml_string); if ( $handle = opendir( $path_to_image_dir ) ) { while (false !== ($file = readdir($handle))) { if ( is_file($path_to_image_dir.'/'.$file) ) { list( $width, $height ) = getimagesize($path_to_image_dir.'/'.$file); $image = $xml_generator->addChild('image'); $image->addChild('path', $path_to_image_dir.'/'.$file); $image->addChild('height', $height); $image->addChild('width', $width); } } closedir($handle); } header("Content-Type: text/xml"); echo $xml_generator->asXML(); ?> Thanks in advance, Matt Link to comment https://forums.phpfreaks.com/topic/238816-creating-xml-file-from-a-file-list/ Share on other sites More sharing options...
fugix Posted June 8, 2011 Share Posted June 8, 2011 have you tried to attempt it yourself at all, or researched? Link to comment https://forums.phpfreaks.com/topic/238816-creating-xml-file-from-a-file-list/#findComment-1227126 Share on other sites More sharing options...
Matrix015 Posted June 8, 2011 Author Share Posted June 8, 2011 I have tried both and I keep messing up the code! So I put it back to the version that works for the images with the hopes that someone can help. The intent was to have images put into a folder and those images displayed without any more end user input. Then have a description to load with each image. Originally I was going to make two seperate files when I realized it could probably be done from one by someone who knows how. Thanks again, Matt Link to comment https://forums.phpfreaks.com/topic/238816-creating-xml-file-from-a-file-list/#findComment-1227129 Share on other sites More sharing options...
Matrix015 Posted June 10, 2011 Author Share Posted June 10, 2011 Hey there, I am still looking for some help with this problem. Thanks, Matt Link to comment https://forums.phpfreaks.com/topic/238816-creating-xml-file-from-a-file-list/#findComment-1227884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.