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

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.