Support » Fixing WordPress » The Image Rotator by Matt

  • hi… i just wanted to say that your random photo gen script is pretty cool. i hope you don’t mind me emailing in receiving help, but i am new to this who thing. it looks pretty simple, but like i said i’m still trying figure out scripting and how to read it.

    this is my site:
    as you can see in the header part you will see ‘ARandom Image’ message. that’s where i’m trying to place it. maybe later down the line when i understand code more, then i’ll start moving it around.

    this is how my header.php looks like:
    <!– End – Flickr Badge –>

    <!– Begin – AdSense –> <!– This is for my personal use and can be removed –> <?php if (function_exists(‘saasmp_wp_header_link_unit’)) saasmp_wp_header_link_unit(); ?> <!– End – AdSense –>

    <div class=”center-widget-title”>This Section is Under Construction!</div><!– This is optional –> <div class=”center-widget”>
    <!– Put your “stuff” below here –>
    <img src=”/random/images/rotate.php” alt=”A Random Image” /> </div>
    <!– Again, please don’t forget this closing ‘div’ –>

    as you can see i’ve tried to follow your instructions to the T. i’ve created a /random/images/ under the public_html and placed my rotate.php with all the test pics i want to post. nothing comes up except the A Random Image comes up. it’s telling me that dropping that code worked, but i can’t seem to figure out how can php look for the images that is in /random/images/. this is how my rotate.php looks like:

    as you can see in the bold i tried following the same direction by leaving the ($folder = “) empty.

    By Matt Mullenweg >
    Inspired by Dan Benjamin >
    Latest version always at:

    // Make this the relative path to the images, like “../img” or “random/images/”.
    // If the images are in the same directory, leave it blank.
    $folder = ”;

    // Space seperated list of extensions, you probably won’t have to change this.
    $exts = ‘jpg jpeg png gif’;

    $files = array(); $i = -1; // Initialize some variables
    if (‘random/images’ == $folder) $folder = ‘random/images’;

    $handle = opendir($folder);
    $exts = explode(‘ ‘, $exts);
    while (false !== ($file = readdir($handle))) {
    foreach($exts as $ext) { // for each extension check the extension
    if (preg_match(‘/\.’.$ext.’$/i’, $file, $test)) { // faster than ereg, case insensitive
    $files[] = $file; // it’s good
    closedir($handle); // We’re not using it anymore
    mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
    $rand = mt_rand(0, $i); // $i was incremented as we went along

    header(‘Location: ‘.$folder.$files[$rand]); // Voila!

    thanks for your time…


  • The topic ‘The Image Rotator by Matt’ is closed to new replies.