Random Image Selector

Discussion in 'Web Design & Coding' started by ~bk, May 27, 2004.

  1. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    Can anyone tell me where I am wrong? I'm totally new at this. I took this code from SPeedY_B's source with his permission. The problem is that the images aren't loading.
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    WHere is it being used so we can see sample output?
     
  3. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    I'm going to use it on my site. Is that what you ask for?
     
  4. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    I don't know if I'm supposed to post this :p but here's the source.

     
  5. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    what does the php code output? this line

    print "<img src=\"images/logos/$file\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";

    PS: There is no such thing as XHTML 1.1 Transitional ;)
     
  6. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    My cousin told me about it. :p
    We'll talk about that later.

    What do you mean by that?
     
  7. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    I mean when you load the webpage what is the output of the code; i.e.

    <img src="images/logos/somepic.jpg" alt="loading" class="noborder" title="bk.ganai.com" />
     
  8. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    It's this, I think:

    <img src="images/logos/logo.jpg" height="203px" width="700px" alt="bk.ganai.com logo"/>
     
  9. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    PHP:
    <?php
    // Random image selector
    srandtime() );
    $files = array();
    if (
    $dir = @opendir("./images/logos/")) {
     while ((
    $file readdir($dir)) !== false) {
      if ( 
    eregi'.(jpeg)$'$file ) ) {
       
    $files[] = $file;
      }
     }
    closedir($dir);
    }
    $file $files[rand() % sizeof$files )];
    print 
    "<img src=\"./images/logos/$file\" alt=\"loading\" title=\"bk.ganai.com\" />";
    ?>
    That should work?

    Also as j79zlr said, transitional doesn't exist, and get rid of all those keywords in the meta tag, they actually don't help search engines (decent ones) seeing as your page is scanned for it's content rather than the meta tags.. it's far too easy to lie about content in meta tags ;)
     
  10. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    What i meant is, that i want a page to go to to see the code it generates so that we can see the output of the script, misspelled variables and whatnot can screw it up./

    Also, your host has to support PHP.
     
  11. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada

    I will remove those tags soon. Would it matter if I change jpeg to jpg?
     
  12. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    My host does support PHP. Here's the page. Hope it helps.
    http://bk.ganai.com/test/main.html
     
  13. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    Doh, try using main.php not main.html :p
     
  14. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
  15. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    Yeah, change it to jpg.. that may be your problem as it's outputting

    Code:
    <img src="images/logos/" alt="loading" class="noborder" title="bk.ganai.com" />
    lacking the file.
     
  16. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    well its working, but its not. :)

    Try this

    PHP:
    print "<img src=\"images/logos/" $file "\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />";
     
  17. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    The print part works (I have it on my page) however its searching for .jpeg files, and bk has (I gather) .jpg... so I'm guessing he needs to just change that part.
     
  18. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    ok, last post :D

    you need to change the images/logos to point to the doc root, since you are in ./main, and your jpegs are jpg's

    PHP:
    <?php
    // Random image selector
    srandtime() );
    $files = array();
    if (
    $dir = @opendir("./images/logos/")) {
    while ((
    $file readdir($dir)) !== false) {
      if ( 
    eregi'.(jpg)$'$file ) ) {
       
    $files[] = $file;
      }
    }
    closedir($dir);
    }
    $file $files[rand() % sizeof$files )];
    print 
    "<img src=\"/images/logos/$file\" alt=\"loading\" title=\"bk.ganai.com\" />";
    ?> 
     
  19. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    Just that or should I replace that line with the old one?
     
  20. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    I'm not sure if the variable is parsed in print, with the above, if that doesn't work, replace with

    PHP:
    print "<img src=\"/images/logos/" $file "\" alt=\"loading\" class=\"noborder\" title=\"bk.ganai.com\" />"