Jump to content

Recommended Posts

Hi there

 

Sorry to just break in here with a dumb question. But I'm looking for a solution for days and nights without success.

 

To be honest, I have no clue about programming, but I'm sure for most of you it's just a fingersnip with a smile...

 

I have a php script that provides a simple XML file as a feed for a photo album(using cooliris with local images). It's only an output on the screen, so I can copy&paste it to a XML file.

 

The problem is, that the tags in the output are written in this form:

 

<thumbnail>thumbs/picture123.jpg</thumbnail>

 

but for the photo album it's required like this:

 

<media:thumbnail url="thumbs/picture123.jpg"/>

 

The script looks like this:

 

----------------------------------------------------------------------------------------------

 

<?php
$path_to_image_dir 
'pl_images'// relative path to your image directory
$path_to_thumbs_dir 'pl_thumbs'// relative path to your image directory
 

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

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

$item $xml_generator->addChild('item'); 
$item->addChild('thumbnail'$path_to_thumbs_dir.'/'.$file); 
$item->addChild('preview'$path_to_image_dir.'/'.$file);
$item->addChild('category''photo'); 
$item->addChild('description'' '); 
}
}

closedir($handle);
}
 

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

 

----------------------------------------------------------------------------------------------

 

The goal is to get a XML coding (for each image) like this:

 

<item>
<title></title>
<description></description>
<link>pics/picture123.jpg</link>
<media:thumbnail url="thumbs/picture123.jpg"/>
<media:content type="image/jpeg" url="pics/picture123.jpg"/>
</item>

 

 

Is there any change to change the syntax of the output accordingly? I think I manage everything, but just not the tag issue.

 

Thank you so much for your help!!!

 

Kind regards,

 

Wolfgang

 

 

 

$item->addChild('thumbnail', $path_to_thumbs_dir.'/'.$file);
That will add a with a value of $path_to_thumbs_dir/$file. What you want is for it to add a in a specific namespace with an empty value and instead an attribute with the URL.

 

The namespace needs to be declared in your XML. Easiest way is

$xml_string = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<items xmlns:media="http://search.yahoo.com/mrss/">
</items>
XML;
Now use addChild() like

$thumbnail = $item->addChild('thumbnail', null, 'http://search.yahoo.com/mrss/');
Then addAttribute().

$thumbnail->addAttribute('url', $path_to_thumbs_dir.'/'.$file);

Hi requinix 
 
You should have seen my big smile when finally the script worked. Thank you so much for this help, I'm so happy that now I can use the cooliris 3D wall photo album with a local installation (photographers portfolio on the PC for situations without internet connection).
 
Just in case that somebody else will also look for a XML RSS feed generator for a cooliris 3D wall photo album that gathers images and thumbnails from folders, here is the script (sorry, did not find out how to make these nice boxes in the posting, so I placed it in a spoiler ::) :
 

/*
=========================================================================
This is a simple XML generator script that generates the items for the
RSS feed to be used for local installations of photo albums with the
3D wall of cooliris (either on your own server or with XAMPP on your PC).

Images and thumbnails to be included automaticall in the RSS feed will
be found from the script but must have the same name and be stored
in two different folders (one for images and one for thumbs).

Just run the script, copy the items from the screen and paste it into
the XML document used for the cooliris photo gallery.
=========================================================================
*/
//
// add below the relative paths to the photos without the last "/"
$path_to_image_dir = 'pl_images'; // relative path to the image directory
$path_to_thumbs_dir = 'pl_thumbs'; // relative path to the thumbnails directory
$path_to_original_dir = 'file://f:\Auslagerung\Fotos\JPG Bearbeitet'; // relative path to the original photo for the link

$xml_string = <<




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) )
{
$item = $xml_generator->addChild('item');
$item->addChild('description', ' ');
$item->addChild('link', $path_to_original_dir.'/'.$file);
$thumbnail = $item->addChild('thumbnail', null, 'http://127.0.0.1/Fotoalbum/');
$thumbnail->addAttribute('url', $path_to_thumbs_dir.'/'.$file);
$content = $item->addChild('content', null, 'http://127.0.0.1/Fotoalbum/');
$content->addAttribute('type', 'image/jpeg');
$content->addAttribute('url', $path_to_image_dir.'/'.$file);
}
}
closedir($handle);
}

header("Content-Type: text/xml");

echo $xml_generator->asXML();
?>




Thank you so much, have a nice weekend
 
Wolfgang

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.