Announcement

Collapse
No announcement yet.

opendir() not working correctly.

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

  • opendir() not working correctly.

    Im basically trying a script going and I've tried it on 2 different servers and one of them (the one I need it to work on) is not working correctly. However, it's working just perfect on the other server. Im basically trying to pull the following code to work (it's for a random image script)

    $folder=opendir(".");

    here's the full code to my random image script:

    It reads it correctly but the result always shows the FIRST image out of 15 in the directory. Anyone know why? Is there a setting that has to be changed on the server side? - I have other scripts that are similar to this that are displaying the first of what's in the directory and are working great on another server...what gives?

    I even tried putting in the virtual directory for it to work (/home/www/dir/1/ or even ./), but to no avail.

    If anyone could help out that would be cool. Thanks!
    Last edited by b00tsauce; Fri 9 Jan '04, 11:01pm.

  • #2
    Originally posted by b00tsauce
    here's the full code to my random image script:
    Uhm, where?

    btw: Could you try the following example taken from php.net:
    PHP Code:
     $d dir(".");
     echo 
    "Handle: ".$d->handle."<br>\n";
     echo 
    "Path: ".$d->path."<br>\n";
     while(
    $entry=$d->read()) {
         echo 
    $entry."<br>\n";
     } 
    Hints & Tips:
    [[vB3] More Spiders / Indexers / Archives for vB3 - list]|[List of one-time-emails to ban]


    http://sfx-images.mozilla.org/affili...efox_80x15.png

    Comment


    • #3
      Originally posted by b00tsauce
      Im basically trying a script going and I've tried it on 2 different servers and one of them (the one I need it to work on) is not working correctly. However, it's working just perfect on the other server. Im basically trying to pull the following code to work (it's for a random image script)

      $folder=opendir(".");

      here's the full code to my random image script:

      It reads it correctly but the result always shows the FIRST image out of 15 in the directory. Anyone know why? Is there a setting that has to be changed on the server side? - I have other scripts that are similar to this that are displaying the first of what's in the directory and are working great on another server...what gives?

      I even tried putting in the virtual directory for it to work (/home/www/dir/1/ or even ./), but to no avail.

      If anyone could help out that would be cool. Thanks!
      Try this

      PHP Code:
      <?php

      $filearray 
      = array();
      $x 0;
      $folder opendir(".");
      while (
      false !== ($file readdir($folder)))
      {
          if (
      $file != '.' AND $file != '..' AND !is_dir($file))
          {
              
      $x++;
              
      array_push($filearray$file);
          }
      }

      $getfilenum rand(0$x);
      echo 
      "<img src='$filearray[$getfilenum]' alt='' />";

      ?>
      Last edited by Silverwolf; Sun 11 Jan '04, 8:56am.

      Comment

      Related Topics

      Collapse

      Working...
      X