Speed up development with full-stack environments for every branch.

Learn More

Dynamic XML file (for imagefolder path) generation using PHP file?

Forked from Hello World.

6 Runs 32 Views 6 Copies

Basic PHP Hello World Example



sashthamanik 2

published 11 months ago

//This code give proper dynamic xml code for corrosponding all type of images
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 = "myimagefolder/"; // 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;
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
         $xmlBody .= '
    <picNum>' . $i . '</picNum>
    <picURL>' . $dir . '' . $file . '</picURL>
      } // 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
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).