Announcement

Collapse
No announcement yet.

Random image PHP script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Random image PHP script

    im sorry if this was asked in another manner somewhere here but i just did about 40 mins of searching, to not find what my question leads to.

    i have a php script that will randomly display an images on webpages - pulling the images from a directory in my site.

    i want to have this image showing in the equivelant space as you already see this above in this site.

    can you please tell me how to directly style in the script-
    becuase for me - i was trying to do it as an include action but doing it as an include is alittle too difficult.

    id like to have the images display randomly above on ALL pages of my VB section


    Thanks-

    any questions - please ask away

  • #2
    For that you would likely want to go to your:

    Admin CP -> Styles & Templates -> Style Manager -> Common Templates (in the menu)

    In your phpinclude_start template, add whatever code or include statement to make use of your random image generator.

    Then in your header template, replace the red code with a variable that is defined by your random image generator:

    Code:
    <!-- logo -->
    <a name="top"></a>
    <table border="0" width="$stylevar[outertablewidth]" cellpadding="0" cellspacing="0" align="center">
    <tr>
    	<td align="$stylevar[left]"><a href="$vboptions[forumhome].php?$session[sessionurl]"><img src="[color=red]$stylevar[titleimage][/color]" border="0" alt="$vboptions[bbtitle]" /></a></td>
    	<td align="$stylevar[right]">
    		&nbsp;
    <!--
      NEW HEADER &amp; NAVBAR
      
      Now that the nav buttons are in the
      navbar template, you can stick whatever
      you like into this space.
    
      This makes it much easier for novice
      admins to customize their header
      template without affecting important
      navigation elements.
    -->
    	</td>
    </tr>
    </table>
    <!-- /logo -->
    
    <!-- content table -->
    $spacer_open
    
    $_phpinclude_output

    Comment


    • #3
      ok im completely missing something here and i just cant see it

      so in my phpinclude_start template i added the following:
      -----------------------------------------------------------------------------------
      <?php
      $dir=opendir("/home/virtual/clubexl/public_html/head/");
      //This is the directory route to the folder
      $directory="http://www.clubexl.com/head/";
      //This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on
      $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]>";
      ?>
      -----------------------------------------------------------------------

      but in my header template over the $stylevar[titleimage]

      what would the variable be?

      am i supposed to change titleimage into the name of the file that i am including?
      If so - then i would need to include it as
      EXAMPLE:
      [http://www.clubexl.com/random.ssi]
      This cant be right is it?

      Comment


      • #4
        Try putting this in the phpinclude_start template:

        PHP Code:
        $dir=opendir("/home/virtual/clubexl/public_html/head/");
        //This is the directory route to the folder
        $directory="http://www.clubexl.com/head/";
        //This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on
        $pattern="\.(gif|jpg|jpeg|png|bmp)$";
        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]");
        $header_title_img "$directory$image[$randNum]"
        Replace $stylevar[titleimage] with $header_title_img.

        Comment


        • #5
          Thank you GREATLY icendium
          it works perfectly
          now all i need do is add the images to the calling folder -

          my prob was i had too much php info in the code " <php.......php>
          and so on

          if you would like to see it working ( so you can gloat)

          goto www.clubexl.com/vb and just refresh the page a few times


          Thanks again

          Comment


          • #6
            Glad to have helped.

            Comment


            • #7
              ok one real quick touch up on this one

              as i look closely at the image dispaly location
              is there way to center it? - i belive that it is sitting inside of a 2 column table (to rotating image)
              but its sitting in the left hand column --
              OK OK so never mind the columns and so on

              i just want to center it - its sitting allocated "left" at the moment


              no rush

              Comment


              • #8
                This is easy.

                Code:
                <!-- logo -->
                <a name="top"></a>
                <table border="0" width="$stylevar[outertablewidth]" cellpadding="0" cellspacing="0" align="center">
                <tr>
                	<td align="[color=red]$stylevar[left][/color]"><a href="$vboptions[forumhome].php?$session[sessionurl]"><img src="$stylevar[titleimage]" border="0" alt="$vboptions[bbtitle]" /></a></td>
                	<td align="$stylevar[right]">
                		&nbsp;
                <!--
                  NEW HEADER &amp; NAVBAR
                  
                  Now that the nav buttons are in the
                  navbar template, you can stick whatever
                  you like into this space.
                
                  This makes it much easier for novice
                  admins to customize their header
                  template without affecting important
                  navigation elements.
                -->
                	</td>
                </tr>
                </table>
                <!-- /logo -->
                
                <!-- content table -->
                $spacer_open
                
                $_phpinclude_output
                Replace $stylevar[left] with center

                Comment


                • #9
                  maybe put in the width and height attributes, it saves the page being redrawn and being a little bit jumpy.
                  My Sites :

                  Comment


                  • #10
                    Sweet. Just made use of this myself. Thanks.

                    Comment


                    • #11
                      nice little script and it works great
                      http://www.weirdpixels.com/images/buttons/button.gif

                      Comment

                      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                      Working...
                      X