Jump to content

Dynamic XML Generation with PHP


nando88

Recommended Posts

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
?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.