trendsetter Posted July 9, 2006 Share Posted July 9, 2006 Hi,How to generate a XML of a list of files inside a directory. My directory contains picture files(.jpg). I am trying to make photo album in flash where i could use XML but I don't want to write the XML code for all the files in a folder.I heard php could be helpful in generating XML. Please help me!Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/ Share on other sites More sharing options...
hvle Posted July 9, 2006 Share Posted July 9, 2006 what's the xml code like?<image1.jpg/>? Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55071 Share on other sites More sharing options...
trendsetter Posted July 9, 2006 Author Share Posted July 9, 2006 its like:[code]<photos> <image photo="photo1"> <title>This is photo 1</title> <image photo="photo2"> <title>This is photo 2</title>...</photos>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55155 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 Well, this should do something like it:I changed the XML a bit, didn't make sense to me.It will run through a folder and create the XML for all the files in the folder,you'll need to add something like fwrite to put it into a file or whatever you want to do.[code]<?php$d = 'images/';$endline = "\n";$dir = opendir($d);$output = '<?xml version="1.0" encoding="ISO-8859-1"?>'.$endline;$output .= '<photos>'.$endline;while($e = readdir($dir)){ if($e!='.' && $e!='..') { $output .= ' <image photo="'.$e.'">'.$endline; $output .= ' <title>'.$e.'</title>'.$endline; $output .= ' </image>'.$endline; }}$output .= '<photos>'.$endline;//code to write the $output to a file[/code]Example $output:[code]<?xml version="1.0" encoding="ISO-8859-1"?><photos> <image photo="Masses.jpg"> <title>Masses.jpg</title> </image> <image photo="Mediteranean.jpg"> <title>Mediteranean.jpg</title> </image> <image photo="Spider.jpg"> <title>Spider.jpg</title> </image> <image photo="Taxi.jpg"> <title>Taxi.jpg</title> </image> <image photo="Tie Hangar.jpg"> <title>Tie Hangar.jpg</title> </image> <image photo="Trainyard.jpg"> <title>Trainyard.jpg</title> </image><photos>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55167 Share on other sites More sharing options...
Daniel0 Posted July 9, 2006 Share Posted July 9, 2006 [quote author=ShogunWarrior link=topic=99947.msg393997#msg393997 date=1152456375]I changed the XML a bit, didn't make sense to me.[/quote]Probably because it had an invalid syntax ;) Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55170 Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 Yeah, that's the one. ;) Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55174 Share on other sites More sharing options...
trendsetter Posted July 10, 2006 Author Share Posted July 10, 2006 thank you very much ShogunWarrior, I will try the code.sorry for the invalid syntax in xml. Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55406 Share on other sites More sharing options...
Daniel0 Posted July 10, 2006 Share Posted July 10, 2006 [quote author=trendsetter link=topic=99947.msg394266#msg394266 date=1152509106]sorry for the invalid syntax in xml.[/quote]Doesn't matter - you are here to learn :D Quote Link to comment https://forums.phpfreaks.com/topic/14086-create-a-xml-file-of-list-of-files-in-a-directory/#findComment-55407 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.