Announcement

Collapse
No announcement yet.

opendir() not working correctly.

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

  • Silverwolf
    replied
    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 11th Jan '04, 9:56am.

    Leave a comment:


  • Stadler
    replied
    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";
     } 

    Leave a comment:


  • b00tsauce
    started a topic opendir() not working correctly.

    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; Sat 10th Jan '04, 12:01am.

Related Topics

Collapse

Working...
X