Javascript image rotation in website

N

number1hatfielder

Hi there,

I am trying to include some javascript in my website which rotates some
stored images. I have attached the code for the index page of my
website as i am having some problems getting it to work. Can anyone see
where i am going wrong? This is my first attempt.

Here is the source script:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>??</title>
<style type="text/css">
<!--
body {
background-color: #006699;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
color: #919297;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #919297;
}
a:hover {
text-decoration: none;
color: #cc6600;
}
a:active {
text-decoration: none;
color: #cc6600;
}
</style>
<?php
$path_to_images = "Images\Adverts\"; // path to your images
$default_img = "highrise.jpg"; // image to display if directory listing
fails

function getRandomImage($path, $img) {
if ( $list = getImagesList($path) ) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($list);
$img = $list[$num];
}
return $path . $img;
}

function getImagesList($path) {
$ctr = 0;
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// can add checks for other image file types here
if ( preg_match("/(\.gif|\.jpg)$/", $img_file) ) {
$images[$ctr] = $img_file;
$ctr++;
}
}
closedir($img_dir);
return $images;
}
return false;
}
?>
</Head>

<td width="590" height="22">
<img src="<?php echo getRandomImage($path_to_images, $default_img) ?>"
alt="">
</td>

I have removed most of the HTML so as to minimise the thread.

Hope this makes some sence!

Regards,
Anthony
 
L

Lee

(e-mail address removed) said:
Hi there,

I am trying to include some javascript in my website which rotates some
stored images. I have attached the code for the index page of my
website as i am having some problems getting it to work. Can anyone see
where i am going wrong? This is my first attempt.

Here is the source script:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>??</title>
<style type="text/css">
<!--
body {
background-color: #006699;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
color: #919297;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #919297;
}
a:hover {
text-decoration: none;
color: #cc6600;
}
a:active {
text-decoration: none;
color: #cc6600;
}
</style>
<?php
$path_to_images = "Images\Adverts\"; // path to your images
$default_img = "highrise.jpg"; // image to display if directory listing
fails

function getRandomImage($path, $img) {
if ( $list = getImagesList($path) ) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($list);
$img = $list[$num];
}
return $path . $img;
}

function getImagesList($path) {
$ctr = 0;
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// can add checks for other image file types here
if ( preg_match("/(\.gif|\.jpg)$/", $img_file) ) {
$images[$ctr] = $img_file;
$ctr++;
}
}
closedir($img_dir);
return $images;
}
return false;
}
?>
</Head>

<td width="590" height="22">
<img src="<?php echo getRandomImage($path_to_images, $default_img) ?>"
alt="">
</td>

I have removed most of the HTML so as to minimise the thread.

You also seem to have removed all of the Javascript.
All I see is PHP.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top