Forum Moderators: coopster

Message Too Old, No Replies

PHP-javascript image rotator problem

         

mr_nabo

11:08 am on Nov 1, 2008 (gmt 0)

10+ Year Member



Hi,

I really hope you can help me with this as I've been tearing my hair out trying to work out how to implement this.

Below is the code for a JQuery + Jquery Innerfade plugin image rotator combined with PHP. I've included both Jquery files in the head of my page and they are working according to some quick tests I did by hard-coding the image url.

However, I'm trying to load the images found in a specific directory of a Joomla installation (hence the Joomla '$this->baseurl' call) and the <li> isn't being generated for some reason. I believe it's to do with the $image_relative_path not being set right, but everything I try doesn't seem to work.

Any ideas on how I can get this working?

Thanks


<?php
// Global Variables
$image_dir = $this->baseurl . '/templates/name/images/home'; // directory on server
$image_relative_path = '/images/home'; // path to images relative to THIS script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '4000'; // seconds each image will display (4000 = 4 seconds)

if($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$ext_bits = explode(".",$file);
foreach($ext_bits as $key => $value){
if(in_array($value,$file_types)){
$image_rotation .= '<li><img src="'.$image_relative_path.'/'.$file.'"></li>';
}
}
}
}
// Close the directory
closedir($handle);
}

?>

<script type="text/javascript">
$(document).ready(function() {
$('#image_rotate').innerfade({
speed: 'slow',
timeout: 4000,
type: 'sequence',
containerheight: '220px'
});
});

</script>

<ul id="image_rotate" style="list-style: none;">
<?php $image_rotation; ?>
</ul>

jatar_k

12:22 pm on Nov 2, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if the <li> line of code doesn't get executed then you need to take a look at the if statement that is around it.

then if the value in your if should be evaluating to true but isn't then look at the foreach around that and see if it is having a problem.