We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32982
    • 674 Posts
    the snippet is (update expand the cell or div to photo size)
    $folder = ’images’;


    $i = 0;
    $imgDir = opendir ($folder);
    while ( $file = readdir( $imgDir ) )
    {
    //checks that file is an image
    $file_type = strrchr( $file, "." );
    $is_image = eregi( "jpg|gif|png",$file_type );

    if ( $file != ’.’ && $file != ’..’ && $is_image )
    { $images[$i++] = $file; }
    }
    closedir ($imgDir);

    srand( (double) microtime()*1000000 );
    $image_name = $folder. ’/’ . $images[rand( 0,sizeof( $images ) -1 )];
    $imgSize = GetImageSize( $image_name );

    //ends script if no images found
    if ( $i == 0 )
    die();

    return"background=’$image_name’$imgSize[3]";


    usage
    put the call to the snippet in the table, div or background into the <> (whithout puting the sice it take from image sice
    example
    <tdvalign="top" [[RandomImage]] bgcolor="#F4F4F4">content</td>
    put [! !] if you want to update on browser reload (dont tested i dont want it)
    change the folder to the direction of your image folder
    [based on etomite random image snippet]
      Jabiertxof (formerly XYZVISUAL)
      My bussines: http://marker.es
      https://www.youtube.com/user/jabiertxof/videos
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      $file_type = strrchr( $file, "." );

      It is possible (not likely, but possible) that this could produce unexpected results, since it finds the first ocurrance of the "." and returns the rest of the string. If your original string had more than one "." you might not get what you were expecting... ie. wedding.gift.tiff would look like a .gif file.

      I prefer this for grabbing the extension of a file:

      $parts = pathinfo($filename);
      $extension = strtolower($parts['extension']);
      


      http://il2.php.net/manual/en/function.pathinfo.php
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32982
        • 674 Posts
        im sorry about my bad english
        but i supose in the folder only be jpg-gif-png files
        im new in php and dont understand well but feel free to optimice the code
        if is posibol
        thanks
          Jabiertxof (formerly XYZVISUAL)
          My bussines: http://marker.es
          https://www.youtube.com/user/jabiertxof/videos
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          This is very odd. I had not seen "strchr" before, so I looked it up. According to the docs, it’s an alias for strstr. And according to the documentation, strstr
          Returns part of haystack string from the first occurrence of needle to the end of haystack.

          Yet when I ran some tests,

          $filename = "test.this.txt";
          echo strchr( $filename, "." );
          echo "<br />";
          echo strstr($filename, ".");
          


          strchr will return ".txt", and not ".this.txt" , while strstr returns .this.txt, as the documentation says. So it’s not really just an alias, it actually behaves differently. And this method is much faster than the pathinfo method. If you just wanted the extension without the ".",

          $extension = substr(strrchr($filename, "."), 1);


          Thank you! I learned something new and useful today!
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 32982
            • 674 Posts
            thanks but only do a little makeup to the original snippet, but
            if i say if you could optimice the code please post it
            because im very new in php and dont understand very well
              Jabiertxof (formerly XYZVISUAL)
              My bussines: http://marker.es
              https://www.youtube.com/user/jabiertxof/videos
              • 4095
              • 372 Posts
              Quote from: xyzvisual at Oct 02, 2005, 06:37 AM

              $folder = 'images';
              

              usage put the call to the snippet in the table, div or background into the <> (whithout puting the sice it take from image sice example <tdvalign="top" [[RandomImage]] bgcolor="#F4F4F4">content</td> put [! !] if you want to update on browser reload (dont tested i dont want it) change the folder to the direction of your image folder
              [based on etomite random image snippet]

              Trying to get this to work, what is the base folder?

              My images are in the assests/site/template_name/people/ directory, what should I put in $folder=’ ’; ? I’m going nuts trying to figure it out by trail and error huh

              I keep getting:
              Parse error: parse error, unexpected T_VARIABLE in /home/emanz/public_html/manager/includes/document.parser.class.inc.php(691) : eval()’d code on line 25
                [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                Admin Sandbox Login: sandbox Password: castle
                • 32982
                • 674 Posts
                i think you need rename images to the folder images are
                hi
                  Jabiertxof (formerly XYZVISUAL)
                  My bussines: http://marker.es
                  https://www.youtube.com/user/jabiertxof/videos
                  • 4095
                  • 372 Posts
                  Quote from: xyzvisual at Mar 17, 2006, 10:01 AM

                  i think you need rename images to the folder images are
                  hi

                  Sorry, another not very clear post by me smiley I tried doing that and had trouble, although I have figgured out what the correct path should be. Wasn’t sure on leading and trailing /’s etc, or what the starting path was, eg assests, root etc

                  It now finds the image but only shows the ALT text, however think that may be a CSS issue.

                  Thanks anyway wink
                    [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                    Admin Sandbox Login: sandbox Password: castle
                    • 32982
                    • 674 Posts
                    i think you need to test whith this
                    assests/site/template_name/people/
                    or
                    assests/site/template_name/people
                    and think all works well
                    if not test like
                    www.yourdomain.com/assests/site/template_name/people/
                    or
                    www.yourdomain.comassests/site/template_name/people
                    or
                    yourdomain.com/assests/site/template_name/people/
                    or
                    yourdomain.com/assests/site/template_name/people
                    hi
                      Jabiertxof (formerly XYZVISUAL)
                      My bussines: http://marker.es
                      https://www.youtube.com/user/jabiertxof/videos
                      • 4273
                      • 356 Posts
                      is there a snippet attached to this post ? or is the code up top the snippet, it wasn’t clear smiley
                        SMF Bookmark Mod - check it out
                        http://mods.simplemachines.org/index.php?mod=350