Jump to content

Creating XML File from a file list


Matrix015

Recommended Posts

Hey all,

I know next to nothing about coding in PHP.

I found this script that allows me to read the contents of a directory and transform it into XML format.

I was wondering if there was a way to have it read two different file types.

Eg. Right now it reads all the files and puts their path into the <image> tag.  I would like to be able to read a text file and put it into a description.

All of this ends up in a Flash Presentation.

 

$path_to_image_dir = 'images'; // relative path to your image directory

$xml_string = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<images> 
</images>
XML;

$xml_generator = new SimpleXMLElement($xml_string);

if ( $handle = opendir( $path_to_image_dir ) ) 
{
    while (false !== ($file = readdir($handle))) 
    {
        if ( is_file($path_to_image_dir.'/'.$file) ) 
        {	
        	

           list( $width, $height ) = getimagesize($path_to_image_dir.'/'.$file);	
           $image = $xml_generator->addChild('image');  
           $image->addChild('path', $path_to_image_dir.'/'.$file); 
          
           $image->addChild('height', $height);    
           $image->addChild('width', $width);        
        }
    }
    closedir($handle);
}

header("Content-Type: text/xml");
echo $xml_generator->asXML();	
?>

 

 

Thanks in advance,

Matt

Link to comment
https://forums.phpfreaks.com/topic/238816-creating-xml-file-from-a-file-list/
Share on other sites

I have tried both and I keep messing up the code!

So I put it back to the version that works for the images with the hopes that someone can help.

The intent was to have images put into a folder and those images displayed without any more end user input.

Then have a description to load with each image.  Originally I was going to make two seperate files when I realized it could probably be done from one by someone who knows how.

 

Thanks again,

Matt

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.