nyguy
12-19-2005, 05:16 AM
Hi there guys. I've been a reader on this site for quite a bit, but this is my first post. This site has already helped me through so many problems!!
I am somewhat of a newbie to site building, but slowly and surely, thanks to this site, I've been getting the hang of it, so I am sorry if my question sounds as if it's coming from a newbie, but it is! :)
I want a random picture to show up each time someone visits my site, or when my site gets refreshed. I have the photos saved to a folder called "randomphoto". I guess the full location would be considered "C:\Documents and Settings\default\My Documents\My Webs\mysite\randomphoto"
Currenly, I have 3 photos in the folder, 1.jpg, 2.jpg, and 3.jpg.
I was told to copy and paste the script below into where I want the random pictures to be displayed..
*/
$dir=opendir("Documents and Settings\default\My Documents\My Webs\mysite\randomphoto");
$directory="";
$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir)
{
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s)
{
if(ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);
//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "<br><img src=\"$directory$image[$randNum]\" $size[3]>";
?>
I got that HTML from a user on the Microsoft FrontPage forums. I stated that I wanted a random picture to be displayed from a particular folder, and I wanted each picture to be roughly 160x159.
Well upon copying and pasting that into where I want the pictures to be displayed, it just doesn't work!
Does anyone know where the problem is?
Any help would be appreciated!!
Thanks!!
I am somewhat of a newbie to site building, but slowly and surely, thanks to this site, I've been getting the hang of it, so I am sorry if my question sounds as if it's coming from a newbie, but it is! :)
I want a random picture to show up each time someone visits my site, or when my site gets refreshed. I have the photos saved to a folder called "randomphoto". I guess the full location would be considered "C:\Documents and Settings\default\My Documents\My Webs\mysite\randomphoto"
Currenly, I have 3 photos in the folder, 1.jpg, 2.jpg, and 3.jpg.
I was told to copy and paste the script below into where I want the random pictures to be displayed..
*/
$dir=opendir("Documents and Settings\default\My Documents\My Webs\mysite\randomphoto");
$directory="";
$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir)
{
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s)
{
if(ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);
//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "<br><img src=\"$directory$image[$randNum]\" $size[3]>";
?>
I got that HTML from a user on the Microsoft FrontPage forums. I stated that I wanted a random picture to be displayed from a particular folder, and I wanted each picture to be roughly 160x159.
Well upon copying and pasting that into where I want the pictures to be displayed, it just doesn't work!
Does anyone know where the problem is?
Any help would be appreciated!!
Thanks!!