nando88 Posted March 4, 2017 Share Posted March 4, 2017 I stumbled upon a video in develop php, that uses php to create a dynamic xml file. I tried to use their code, and modify to my needs but I wasn't able to. I need a php file that creates an xml with all the subfolders in a folder and the images inside those subfolders. Can someone please help me get this working? Thanks. This is what I have tried so far: http://www.developphp.com/video/PHP/Image-Gallery-PHP-Loop-Files-Dynamic-XML-Tutorial <?php header("Content-Type: text/xml"); // set the content type to xml // Initialize the xmlOutput variable $xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $dir = "../images/"; // Specify Directory where images are $xmlBody .= "<XML>"; // Start XMLBody output // open specified directory using opendir() the function $dirHandle = opendir($dir); // Create incremental counter variable if needed $i = 0; $root = '../images'; $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" ); $paths = array($root); foreach ($iter as $path => $dir) { if ($dir->isDir()) { $paths[] = $path; if(!is_dir($file) && strpos($file, '.jpg')){ $i++; // increment $i by one each pass in the loop $xmlBody .= <'$paths[$iter]'>' '<'$paths[$iter]'> <picNum>' . $i . '</picNum> <picURL>' . $dir . '' . $file . '</picURL> </Picture>'; } // close the if statement } } while ($file = readdir($dirHandle)) { // if file is not a folder and if file name contains the string .jpg if(!is_dir($file) && strpos($file, '.jpg')){ $i++; // increment $i by one each pass in the loop } // close the if statement } // End while loop closedir($dirHandle); // close the open directory $xmlBody .= "</XML>"; echo $xmlBody; // output the gallery data as XML file for flash ?> Quote Link to comment https://forums.phpfreaks.com/topic/303348-dynamic-xml-generation-with-php/ Share on other sites More sharing options...
requinix Posted March 4, 2017 Share Posted March 4, 2017 That code is all sorts of messed up. Are you sure you copied it down correctly, either in your own code or into your post? Quote Link to comment https://forums.phpfreaks.com/topic/303348-dynamic-xml-generation-with-php/#findComment-1543731 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.