Jump to content

Need help with php/xml


music_lp90

Recommended Posts

Hi, I'm trying to create a photo gallery using php to create xml that holds the data for the gallery. The xml is displaying the path to the image correctly, but I am not able to get the image into the html table.Here's the php/xml:

<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"; ?><?php require_once("functions.php"); ?><gallery>	<?php xmlImage(scan_sort_dir("images/xmlGallery/")); ?></gallery>

Here are the functions php is calling:

<?php	//Get the files from the directory	function scan_sort_dir($path) {	$dir = $path;	$dh  = opendir($dir);	while (false !== ($filename = readdir($dh))) {		$files[] = $path . $filename;	}	return $files;	} ?><?php	//insert images into xml file	function xmlImage($passFiles) {		$files = $passFiles;		for ($i = 0; $i < count($files); $i++) {			if (!is_dir($files[$i])) {					echo "<image>" . $files[$i] . "</image>";			}		}	}?>

Here is the html:

<xml id="galleryData" src="xmlGallery.php" /><table datasrc="#galleryData">	<tr>		<td><p>Slide Show</p></td>	</tr>	<tr>		<td><img datafld="image"/></td>	</tr></table>

If you want to see how the xml displays when viewed in a web page you can see it here: http://www.grantportfolio.com/xmlGallery.php This is helpful because it shows just the xml without all of the php.To see the what the html page is displaying you can go here: http://www.grantportfolio.com/xmlGallery.htmlThanks for your help!

Link to comment
Share on other sites

I was about to ask if you can actually use PHP's DOM, as that would be easier on the larger scale, but then again, that's not the issue here really.First problem, even if you were able to get this working, it would only work in IE, because data islands (the method for displaying XML data that you're using) is an IE only feature, and it's not how XML is supposed to be used.Next problem, as far as I'm aware, data islands can only fill in text values. You're instead trying to fill in the source adress of an image, which traditionally goes in the "src" attribute, and that's not doable with data islands.If what you're trying to do is a dynamic gallery that loads the next images without a page reload, then what you'd like to check out is the JavaScript XMLHtttpRequest() object instead. With it, JavaScript can get the XML generated by PHP, and change the "src" of the image to the value of the appropriate element. If you're really clever, you'll also use that same object to then lauch a few new subsequential requests for the next images, so that you "pre-cache" them i.e. download them while the user is looking at the current picture so that when they ask for the next, it will appear instantly.

Link to comment
Share on other sites

Thanks boen. I had seen this done on a tutorial from Lynda.com, but I don't think it mentioned anything about the limited support for it. So, I guess I won't do it this way. It seemed like a pretty handy way to do it though. The guy was inserting images using xml and I thought it was the same way I was doing it, but for some reason its not working for me. Thanks for the javascript suggestion, I think I'm going to give that a try.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...