www.webdeveloper.com
Results 1 to 2 of 2

Thread: Image Randomiser Problems...

  1. #1
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    44

    Image Randomiser Problems...

    Hi all,

    I'm having trouble on the following page;

    www.maddenbrosltd.com/test.html

    ...as I'm trying to display random header images with the following php file but it just won't seem to work...

    www.maddenbrosltd.com/rotate/rotate.php

    The php file is is in a folder with 6 other .jpgs..

    Can anyone help?

    Many thanks in advance!
    Regards,

    Barry

    www.barrymcgee.net

  2. #2
    Join Date
    May 2006
    Location
    North of the South Pole
    Posts
    590
    It seems to work fine for some reason my browser downloaded the php file so I could see your code and that code is way much more than you need. Here's some code 1/10 the size:

    PHP Code:
    <?php

    $dir 
    "images/";

    $allfiles glob($dir."*");
    foreach(
    $allfiles as $k => $v){
        
    $info pathinfo($v);
        switch(
    $info['extension']){
            case 
    "gif":
            case 
    "png":
            case 
    "jpg":
            case 
    "jpeg":
                break;
            default:
                
    array_splice($allfiles$k1);
                break;
        }
    }
    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';
    $rand rand(0count($allfiles)-1);
    $file $allfiles[$rand];
    $info pathinfo($file);
    header('Content-Type: '.$extList[$info['extension']]);
    readfile($file);

    ?>
    Not guaranteed to work, but it's worth a try.
    Last edited by shane.carr; 09-04-2006 at 03:27 PM.
    "I have no special talent. I am only passionately curious." Albert Einstein

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles