Results 1 to 2 of 2

Thread: Random Images don't show up - help!

  1. #1
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Random Images don't show up - help!

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

  2. #2
    Join Date
    Aug 2005
    Posts
    200
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    <script language="javascript">
    <!--
    //-- Generate a random number between 0 and 1.
    function randomNum(max) {
    var rNum=NaN
    while (isNaN(rNum)) {
    rNum=Math.floor(Math.random()*(max))
    }
    return rNum
    }

    var pic = new Array()
    pic[0]="folder/1.jpg"
    pic[1]="folder/2.jpg"
    pic[2]="folder/3.jpg"
    pic[3]="folder/4.jpg"
    pic[4]="folder/5.jpg"
    pic[5]="folder/6.jpg"
    pic[6]="folder/7.jpg"
    pic[7]="folder/8.jpg"
    pic[8]="folder/9.jpg"
    pic[9]="folder/10.jpg"
    pic[10]="folder/11.jpg"
    pic[11]="slfolder/12.jpg"
    pic[12]="folder/13.jpg"
    pic[13]="folder/14.jpg"
    pic[14]="folder/15.jpg"
    pic[15]="folder/16.jpg"
    pic[16]="folder/17.jpg"
    pic[17]="folder/18.jpg"
    pic[18]="folder/19.jpg"
    pic[19]="folder/20.jpg"
    pic[20]="folder/21.jpg"
    pic[21]="folder/22.jpg"
    pic[22]="folder/23.jpg"
    pic[23]="folder/24.jpg"
    pic[24]="folder/25.jpg"
    pic[25]="folder/26.jpg"
    pic[26]="folder/27.jpg"












    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_findObj(n, d) { //v3.0
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }

    function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>




    Try this one. It works great for me. past it under the <head> tag. JF

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •