Posted By

Don_Jarmo on 10/25/11


Tagged

xml images


Versions (?)

Image files to xml


 / Published in: PHP
 

Checks for image files in directory and creates a XML file of the contents

  1. <?php
  2. header("Content-Type: text/xml"); //set the content type to xml
  3. // Initialize the xmlOutput variable
  4. $xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  5. $dir = "images/gallery1/"; // Specify Directory where images are
  6. $xmlBody .= "<XML>"; // Start XMLBody output
  7. // open specified directory using opendir() the function
  8. $dirHandle = opendir($dir);
  9. // Create incremental counter variable if needed
  10. $i = 0;
  11. while ($file = readdir($dirHandle)) {
  12. // if file is not a folder and if file name contains the string .jpg
  13. if(!is_dir($file) && strpos($file, '.jpg')){
  14. $i++; // increment $i by one each pass in the loop
  15. $xmlBody .= '
  16. <Picture>
  17. <picNum>' . $i . '</picNum>
  18. <picURL>' . $dir . '' . $file . '</picURL>
  19. </Picture>';
  20. } // close the if statement
  21. } // End while loop
  22. closedir($dirHandle); // close the open directory
  23. $xmlBody .= "</XML>";
  24. echo $xmlBody; // output the gallery data as XML file for flash

Report this snippet  

You need to login to post a comment.