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