?
Solved

Sort dirs by creation date

Posted on 2003-03-11
53
Medium Priority
?
347 Views
Last Modified: 2008-02-01
On my site, I have a php page that lists all directories. How can I sort that list in creation order?

/Helen
0
Comment
Question by:archker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 30
  • 23
53 Comments
 
LVL 15

Expert Comment

by:VGR
ID: 8111082
the function to get their creation time is (surprinsingly) ctime()
to sort them requires a usort() trick or a "normal" sorting, or some other technique

I suggest you let the OS do the work like this :

   $directory2=str_replace('/','\\',$directory);
   $d = @popen ("dir /ON /B $directory2", "r"); // triés par ordre alphabétique
   while (!feof ($d)) {
    $buffer = fgets($d, 4096);
    $entry=chop($buffer);
    if (($entry<>'.') and ($entry<>'..') and ($entry<>'')) {
  // do your stuff on $entry
  // you may want to use is_dir() to treat only directories (but not . nor ..)
    } // if affichage
   } // while
   $toto=@pclose($d);
0
 

Author Comment

by:archker
ID: 8111955
Alright, that worked somewhat good, but, maybe I should have been more specific. This is the code I use for the page to generate a table with names based on text-files in dirs.

<?php

$numberOfColumn=3;

function getAlbumTableList($before="", $after="") {
     global $browse;
     echo "<div id=\"albumbrowser\">\n$before";
     print_table($browse);
     echo "$after</div>";
}

# ****************************************************************************************
# 'Private' functions
# ****************************************************************************************
function print_table($starting_directory, $toBePrinted="") {
     global $display_abstract, $album_php_config, $lang, $numberOfColumn;

     $to_print="";
     include('inc/album_config.php');

     $directory_link=$starting_directory;
     if ($directory_link==".") {
          $directory_link="";
     }

     if (file_exists("$directory_link$album_php_config")) {
          include("$directory_link$album_php_config");
     }
     
     $is_picture_directory=false;
     $down_printed=false;
     $all_dir = array();
     if($d_obj = dir($starting_directory)) {
          while($this_entry = $d_obj->read()) {
               if ($this_entry != "." && $this_entry != ".." && $this_entry != $thumb_dir) {
                    if(is_dir("$directory_link$this_entry")) {
                         if (isValidPictureDirectory("$directory_link$this_entry")) {
                              $all_dir[] = $this_entry;
                         }
                    }
                    if (is_file("$directory_link$this_entry")) {
                         if (isValidPictureFile("$directory_link$this_entry") != boolean) {
                              $is_picture_directory=true;
                         }
                    }    
               }
          }
          $d_obj->close();
     } else {
          echo "Error!  Couldn't list directory $starting_directory for some reason!<br />";
          exit;
     }
     $keep_going=true;
     $x=0;
     $y=0;
     $z=0;
     $width=round(100/$numberOfColumn);
     echo "<table id=\"albumsListTable\" width=\"476\">\n";
     while ($keep_going) {
          echo "   <tr class=\"albumsLine\">\n";
          while ($y < $numberOfColumn) {
               if ($z<sizeof($all_dir)) {
                    echo "<td class=\"albumsCell\" width=\"$width%\" align=\"center\" valign=\"top\">";
                    echo "<a href=\"album.php?album=";
                    echo $all_dir[$z];
                    echo "\">";
                    echo getAlbumTitleText("$all_dir[$z]/");
                } else {
                    echo "<td class=\"noAlbumsCell\" width=\"$width%\" align=\"center\" valign=\"top\">&nbsp;</td>\n";
                    $keep_going=false;
               }
               $y++;
               $z++;
          }
          $x++;
          $y=0;
          echo "   </tr>\n";
     }
     echo "</table>\n";
     
}
?>

Any way to make it sort the dirs, (i.e. the info in the album.txt-file), chronological?

/Helen
0
 
LVL 15

Expert Comment

by:VGR
ID: 8112309
note that this line doesn't work as you expected :
        if ($this_entry != "." && $this_entry != ".." && $this_entry != $thumb_dir) {

$thumb_dir is undefined in print_table()
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Expert Comment

by:VGR
ID: 8112340
to solve your ordering problem, I would replace these lines :

  if($d_obj = dir($starting_directory)) {
    while($this_entry = $d_obj->read()) {

by those :

  if($d_obj = @popen ("dir /ON /B $starting_directory", "r") ) {
  while (!feof ($d_obj)) {
   $buffer = fgets($d_obj, 4096);
   $this_entry=chop($buffer);

and I would replace also
$d_obj->close();
by
$toto=@pclose($d_obj);
0
 

Author Comment

by:archker
ID: 8114580
sorry, didn't work. It dosn't show any columns.
I'm really bad at php, so please be really specific when you ask me to change code =)
0
 
LVL 15

Expert Comment

by:VGR
ID: 8115087
ok, full source then

<?php

$numberOfColumn=3;

function getAlbumTableList($before="", $after="") {
    global $browse;
    echo "<div id=\"albumbrowser\">\n$before";
    print_table($browse);
    echo "$after</div>";
}

# ****************************************************************************************
# 'Private' functions
# ****************************************************************************************
function print_table($starting_directory, $toBePrinted="") {
    global $display_abstract, $album_php_config, $lang, $numberOfColumn;

    $to_print="";
    include('inc/album_config.php');

    $directory_link=$starting_directory;
    if ($directory_link==".") {
         $directory_link="";
    }

    if (file_exists("$directory_link$album_php_config")) {
         include("$directory_link$album_php_config");
    }
   
    $is_picture_directory=false;
    $down_printed=false;
    $all_dir = array();

if($d_obj = @popen ("dir /ON /B $starting_directory", "r") ) {
 while (!feof ($d_obj)) {
  $buffer = fgets($d_obj, 4096);
  $this_entry=chop($buffer);
              if ($this_entry != "." && $this_entry != ".." && $this_entry != $thumb_dir) {
                   if(is_dir("$directory_link$this_entry")) {
                        if (isValidPictureDirectory("$directory_link$this_entry")) {
                             $all_dir[] = $this_entry;
                        }
                   }
                   if (is_file("$directory_link$this_entry")) {
                        if (isValidPictureFile("$directory_link$this_entry") != boolean) {
                             $is_picture_directory=true;
                        }
                   }    
              }
         }
$toto=@pclose($d_obj);
    } else {
         echo "Error!  Couldn't list directory $starting_directory for some reason!<br />";
         exit;
    }
    $keep_going=true;
    $x=0;
    $y=0;
    $z=0;
    $width=round(100/$numberOfColumn);
    echo "<table id=\"albumsListTable\" width=\"476\">\n";
    while ($keep_going) {
         echo "   <tr class=\"albumsLine\">\n";
         while ($y < $numberOfColumn) {
              if ($z<sizeof($all_dir)) {
                   echo "<td class=\"albumsCell\" width=\"$width%\" align=\"center\" valign=\"top\">";
                   echo "<a href=\"album.php?album=";
                   echo $all_dir[$z];
                   echo "\">";
                   echo getAlbumTitleText("$all_dir[$z]/");
               } else {
                   echo "<td class=\"noAlbumsCell\" width=\"$width%\" align=\"center\" valign=\"top\">&nbsp;</td>\n";
                   $keep_going=false;
              }
              $y++;
              $z++;
         }
         $x++;
         $y=0;
         echo "   </tr>\n";
    }
    echo "</table>\n";
   
}
?>
0
 
LVL 15

Expert Comment

by:VGR
ID: 8115094
as far as columns are concerned, it shouldn't change anything. I only modified the way you get $this_entry
0
 

Author Comment

by:archker
ID: 8117678
Still, doesn't display anything.
Maybe there's another way?
0
 

Author Comment

by:archker
ID: 8117949
Cant use fileatime to compare it and display the oldest first?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8117960
1)"Alright, that worked somewhat good" : so my code does display the files (and directories) in the order you want
2)"Still, doesn't display anything." : ???

I just slightly modified your code (supposed to display something, right ? :D ) so that files (rather "directories") are taken differently. The rest (display etc) is 100% your code

So I don't understand.

PS : toBePrinted is not used at all in print_table()
PPS : I'm trying to run the script, yours, mine, and the combination. Later.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8117969
could I see file 'inc/album_config.php' ?
0
 

Author Comment

by:archker
ID: 8118046
perhaps adopt this code???
Found it somehwre but cant apply it...



$directory = "$album/";
$files = array();
$columnSpan = 4;

$handle = opendir($directory);
$i = 0;
while($filename = readdir($handle))
{
if ($filename <> '.' && $filename <> '..')
{
$files[$i] = array(filemtime($directory .$filename), $filename);
$i ++;
}
}

arsort($files);
reset($files);
0
 
LVL 15

Expert Comment

by:VGR
ID: 8118075
yes archker, but it should use ctime() not mtime() AFAIK
0
 

Author Comment

by:archker
ID: 8118249
then how would the code look in the whole context?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8118689
As I wrote above when I said "full code"

I'm still waiting for the 'inc/album_config.php' file to be able to run the scripts


Listening...
0
 

Author Comment

by:archker
ID: 8119430
well, it just doesn't display any colums, it's just blank, but at least it doesnt say any error messeges, so it's somewhat good I guess =)

you can get allt the other files from http://www.chevillat.ch/sp/soft/picsPHP/  I modified it of cource ALOT but all the files u need should be there.

/Helen
0
 
LVL 15

Expert Comment

by:VGR
ID: 8122218
0
 
LVL 15

Expert Comment

by:VGR
ID: 8122226
I need the PHP script, NOT THE HTML FILE THAT WILL BE RETURNED IN MY BROWSER
0
 
LVL 15

Expert Comment

by:VGR
ID: 8122237
I need the PHP script, NOT THE HTML FILE THAT WILL BE RETURNED IN MY BROWSER
0
 
LVL 15

Expert Comment

by:VGR
ID: 8122281
I need the PHP script, NOT THE HTML FILE THAT WILL BE RETURNED IN MY BROWSER
0
 
LVL 15

Expert Comment

by:VGR
ID: 8122317
I need the PHP script, NOT THE HTML FILE THAT WILL BE RETURNED IN MY BROWSER

I tried to directly include the above URL but to no avail

It's not very serious to ask for help on a script that can't be run 8-)
0
 

Author Comment

by:archker
ID: 8122695
It can be run.... sigh, but it consist of multiple files!
(download the entire thing from http://www.chevillat.ch/sp/soft/picsPHP/download.php ) that's what I meant.

But sure =), if you think the album_config will help:

<?php

     # ****************************************************************************************
     #
     # ****************************************************************************************
     # number of lines and columns per page for the pictures index
     $lines=4;
     $cols=3;
     
     # number besides the thumbnail
     # 1: yes, 2: no
     $display_number=0;
     
     # stylesheet
      $album_stylesheets=array('default.css');
     
     # Are the thumbnails available somewhere ?
     # 1: yes, 0: no
     # If not the original pictures will be resized by the browser (not suitable)!
     $thumb=1;

     # if yes, which repertory are they ? and what is the 'prefix' of the thumbnails ?
     $thumb_dir="";
     $thumb_prefix="t_";

     # if not, what percentage the thumbnails should be ?
     # 100%= the thumbnails are the same size than the picture itself.
     # 50%=half of the original size
     # 0%=not a valid value
     $thumb_resize=50;
     

     $nb_thumb_navigation=5;
     
     
?>
0
 
LVL 15

Expert Comment

by:VGR
ID: 8122990
sorry for having not found download.php by myself 8-))
testing... I hope default.css is not essential also 8-)
0
 
LVL 15

Expert Comment

by:VGR
ID: 8123002
Sorry, but some definition of those variables is missing :

   if (file_exists("$directory_link$album_php_config")) {
        include("$directory_link$album_php_config");
0
 
LVL 15

Expert Comment

by:VGR
ID: 8123016
in your script, the variables $directory_link and $album_php_config are not set, are not declared, are not set up by an include file, are not passed as parameters to the print_table() function, are not global variables (no session_start(); at the beginning)...

HOW COULD THIS WORK ???!!??
0
 
LVL 15

Expert Comment

by:VGR
ID: 8123078
Sorry also, but your downloaded files produce this :

Warning: getimagesize: Unable to open '/' for reading. in ***\picsphp\inc\functions.php on line 223

I don't have time to re-configure all your includes

I maintain that IF your code did produce results before we touched it, and IF my code did "perform well" (sic) for sorting the directories the way you wanted, THEN combining both the way I did above SHOULD WORK.
0
 

Author Comment

by:archker
ID: 8128989
hmmm, odd. Becouse when I use the code you gave me, the table that displeyed all dirs just comes up totally blank.

Go here to get all the files I use, if you want to help me:
http://www.fantasygallery.net/php.zip

I really appriciate the help you're giving me.
I really don't think there's alot of undefined functions, u just have to look at all the php-pages included. It's sort-of annoingly complicated I guess.

(explaination: there is an index.php and and album.php and a picture.php that calls for several files that in their turn calls for several files, which has several functions and draws their definitions from perhaps not their own files but other files which also are included.......)
It is index.php that calls for this list of directiories.

/Helen
0
 
LVL 15

Expert Comment

by:VGR
ID: 8131008
i would like to see the HTML source of the page "totally blank", PLEASE
0
 

Author Comment

by:archker
ID: 8131239
that's the index.php file in the zip file
0
 
LVL 15

Expert Comment

by:VGR
ID: 8131285
not the PHP source, the source (HTML code) of the GENERATED PAGE

execute my script, it comes "blank" - fine.
Do rightclick/view source and copy-paste this here

thanks
0
 

Author Comment

by:archker
ID: 8131357
or I mean: fantasygallery.net =) changed the code to your model now...

(btw it's the album_special_functions.php which holds the code for the table)
0
 

Author Comment

by:archker
ID: 8131428
perhaps you have to have a few subdirectories to where you place the files. IE a few dirs with images, and in each dir a file named album.txt only with one line of text, fx a name or so. =)
0
 

Author Comment

by:archker
ID: 8131439
sorry, I keep misunderstanding you. I guess I'm just really stupid sometimes.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8131759
run my script "that performed well"
the page is supposed to come out BLANK
GET THE SOURCE HTML OF THAT PAGE BY RIGHT-CLICKING IN THE BROWSER'S WINDOW AND choosing "view page source"

and COPY-PASTE WHAT YOU OBTAIN HERE
0
 

Author Comment

by:archker
ID: 8134847
sure I just figured it's be easier if you looked at the page instead of posting alot of unnessesery code here...


<html>
<head>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <title>Fantasy Art Gallery</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="inc/css/default.css" rel="stylesheet" type="text/css">
<link REL="SHORTCUT ICON" HREF="http://www.fantasygallery.net/inc/gal.ico">
</head>

<div align="left">

  <table width="720" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td align="left" valign="top" style="background-color:#000000; background-image:  url(/inc/drake.gif);background-repeat: no-repeat;">

  <table width="720" cellspacing="0" cellpadding="0" style="border:3px;border-style:solid;border-color:#000000">
    <tr>
      <td width="121" height="112">
       </td>
       <td valign="bottom" width="599" height="112" align="left" background="/inc/logo.jpg"><img src="/inc/black.gif" height="4" width="100%" style="border:0px"></td>
    </tr>
    <tr>
      <td width="121"><img src="/inc/invis.gif" width="121" style="border:0px"></td>
      <td background="/inc/bg.gif" valign="top" align="right" width="599">
<div align="right">
        <table width="536" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center">
<br>
--- ::: ------ :::: --------- :::::::::::::::::::::::::: --------- :::: ------ ::: ---
<br>
<br>
<br>
<br>
--- ::: ------ :::: --------- :::::::::::::::::::::::::: --------- :::: ------ ::: ---
<br>
<br>
<br>
<br>
<div id="albumbrowser">
<table id="albumsListTable" width="476">
   <tr class="albumsLine">
<td class="noAlbumsCell" width="33%" align="center" valign="top">&nbsp;</td>
<td class="noAlbumsCell" width="33%" align="center" valign="top">&nbsp;</td>
<td class="noAlbumsCell" width="33%" align="center" valign="top">&nbsp;</td>
   </tr>
</table>
</div>--- ::: ------ :::: --------- :::::::::::::::::::::::::: --------- :::: ------ ::: ---
<br>
<br>
Old masters will be added soon
<br>
<br>
--- ::: ------ :::: --------- :::::::::::::::::::::::::: --------- :::: ------ ::: ---
<br>
<br>
     </td>
          </tr>
        </table>
</div>
      </td>
    </tr>
    <tr>
      <td width="121"><img src="/inc/invis.gif" width="121" style="border:0px"></td>
      <td background="/inc/down.jpg" valign="top" align="right" width="599" height="116">

</td>
    </tr>
  </table>
      </td>
    </tr>
  </table>

</div>
</body>
</html>
0
 
LVL 15

Expert Comment

by:VGR
ID: 8138442
so sizeof($all_dir)) =0 as per your code

I suggest to debug the part just before :

}
//test
$DEBUGTEST=1;
//
   
    $is_picture_directory=false;
    $down_printed=false;
    $all_dir = array();
if ($DEBUGTEST==1) echo "all_dir[] cleaned<BR>";
    if($d_obj = dir($starting_directory)) {
if ($DEBUGTEST==1) echo "ok getdir of '$starting_directory'<BR>";
         while($this_entry = $d_obj->read()) {
if ($DEBUGTEST==1) echo "entry '$this_entry' found <BR>";
              if ($this_entry != "." && $this_entry != ".." && $this_entry != $thumb_dir) {
if ($DEBUGTEST==1) echo "entry '$this_entry' accepted as candidate<BR>";
                   if(is_dir("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "entry '$this_entry' is a directory<BR>";
                        if (isValidPictureDirectory("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "entry '$this_entry' passed isValidPictureDirectory, added to all_dir<BR>";
                             $all_dir[] = $this_entry;
                        }
                   }
                   if (is_file("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "entry '$this_entry' is a file<BR>";
                        if (isValidPictureFile("$directory_link$this_entry") != boolean) {
if ($DEBUGTEST==1) echo "entry '$this_entry' passed absurd test<BR>";
                             $is_picture_directory=true;
                        }
                   }    
              }
         }
         $d_obj->close();
if ($DEBUGTEST==1) echo "end of directories search<BR>";
    } else {
         echo "Error!  Couldn't list directory $starting_directory for some reason!<br />";
         exit;
    }
   


PS : what does mean this code part ???
if (isValidPictureFile("$directory_link$this_entry") != boolean)

boolean is undefined !
is isValidPuctureFile returns a Boolean, then the test should be written as :
if (isValidPictureFile("$directory_link$this_entry"))
0
 

Author Comment

by:archker
ID: 8140065
yes well, boolean was just a leftover from some insane moment of mine.

I'll try and debug now...
0
 

Author Comment

by:archker
ID: 8140154
well, it finds everything when I run my old code of course:
all_dir[] cleaned
ok getdir of '.'
entry '.' found
entry '..' found
entry 'lockwood' found
entry 'lockwood' accepted as candidate
entry 'lockwood' is a directory
entry 'lockwood' passed isValidPictureDirectory, added to all_dir
entry 'alexander' found
entry 'alexander' accepted as candidate
entry 'alexander' is a directory
entry 'alexander' passed isValidPictureDirectory, added to all_dir
entry 'myalbums.php' found
entry 'myalbums.php' accepted as candidate
entry 'myalbums.php' is a file

und so weiter...

end of directories search

 but when I run the code you altered it only says:

all_dir[] cleaned
ok getdir of '.'
end of directories search


?

0
 
LVL 15

Expert Comment

by:VGR
ID: 8141753
ok, just to make sure we write about the same code, I reproduce what I think should be the code so far

function print_table($starting_directory, $toBePrinted="") {
   global $display_abstract, $album_php_config, $lang, $numberOfColumn;

   $to_print="";
   include('inc/album_config.php');

//test
   $DEBUGTEST=1;
//

   $directory_link=$starting_directory;
   if ($directory_link==".") {
        $directory_link="";
   }

   if (file_exists("$directory_link$album_php_config")) {
        include("$directory_link$album_php_config");
   }
   
   $is_picture_directory=false;
   $down_printed=false;
   $all_dir = array();
if ($DEBUGTEST==1) echo "VGR all_dir[] cleaned<BR>";
if($d_obj = @popen ("dir /ON /B $starting_directory", "r") ) {
if ($DEBUGTEST==1) echo "VGR ok getdir of '$starting_directory'<BR>";
while (!feof ($d_obj)) {
 $buffer = fgets($d_obj, 4096);
 $this_entry=chop($buffer);
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' found <BR>";
             if ($this_entry != "." && $this_entry != ".." && $this_entry != $thumb_dir) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' accepted as candidate<BR>";
                  if(is_dir("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' is a directory<BR>";
                       if (isValidPictureDirectory("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' passed isValidPictureDirectory, added to all_dir<BR>";

                            $all_dir[] = $this_entry;
                       }
                  }
                  if (is_file("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' is a file<BR>";
                       if (isValidPictureFile("$directory_link$this_entry")) { // CHECK TEST
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' is valid picture file<BR>";
                            $is_picture_directory=true;
                       }
                  }    
             }
        }
$toto=@pclose($d_obj);
if ($DEBUGTEST==1) echo "VGR end of directories search, ".count($all_dir)." elements found.<BR>";
   } else {
        echo "Error!  Couldn't list directory $starting_directory for some reason!<br />";
        exit;
   }
   $keep_going=true;
   $x=0;
   $y=0;
   $z=0;
   $width=round(100/$numberOfColumn);
   echo "<table id=\"albumsListTable\" width=\"476\">\n";
   while ($keep_going) {
        echo "   <tr class=\"albumsLine\">\n";
        while ($y < $numberOfColumn) {
             if ($z<sizeof($all_dir)) {
                  echo "<td class=\"albumsCell\" width=\"$width%\" align=\"center\" valign=\"top\">";
                  echo "<a href=\"album.php?album=";
                  echo $all_dir[$z];
                  echo "\">";
                  echo getAlbumTitleText("$all_dir[$z]/");
              } else {
                  echo "<td class=\"noAlbumsCell\" width=\"$width%\" align=\"center\" valign=\"top\">&nbsp;</td>\n";
                  $keep_going=false;
             }
             $y++;
             $z++;
        }
        $x++;
        $y=0;
        echo "   </tr>\n";
   }
   echo "</table>\n";
   
}
?>


just fix the "strange test with != boolean" and run it.
Thanks
0
 

Author Comment

by:archker
ID: 8142146
now it says

VGR all_dir[] cleaned
VGR ok getdir of '.'
VGR entry '' found
VGR end of directories search, 0 elements found.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8142228
Well, I tested this code :
<?
$directory='.';
  $directory2=str_replace('/','\\',$directory);
  $d = @popen ("dir /ON /B $directory2", "r"); // triis par ordre alphabitique
  while (!feof ($d)) {
   $buffer = fgets($d, 4096);
   $entry=chop($buffer);
   if (($entry<>'.') and ($entry<>'..') and ($entry<>'')) {
 // do your stuff on $entry
echo "found $entry<BR>";
 // you may want to use is_dir() to treat only directories (but not . nor ..)
   } // if affichage
  } // while
  $toto=@pclose($d);
?>

and it produced :
found aigle2
found Babou
found bebel
found bin
found blank.html
found discserver
found doc
<snip>
found favicon.ico
found testdir.php // this script
found testprint.bak

So you can see that I have all the directories, all the files...

The instrumented code should work... On Windows platform...

I now copy-pasted the code you tried and I did this (I commented out some parts because of missing functions etc)
<?
$starting_directory='.';
$DEBUGTEST=1;

  $all_dir = array();
if ($DEBUGTEST==1) echo "VGR all_dir[] cleaned<BR>";
if($d_obj = @popen ("dir /ON /B $starting_directory", "r") ) {
if ($DEBUGTEST==1) echo "VGR ok getdir of '$starting_directory'<BR>";
while (!feof ($d_obj)) {
$buffer = fgets($d_obj, 4096);
$this_entry=chop($buffer);
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' found <BR>";
            if ($this_entry != "." && $this_entry != ".." && $this_entry != $thumb_dir) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' accepted as candidate<BR>";
                 if(is_dir("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' is a directory<BR>";
//                      if (isValidPictureDirectory("$directory_link$this_entry")) {
//if ($DEBUGTEST==1) echo "VGR entry '$this_entry' passed isValidPictureDirectory, added to all_dir<BR>";
//
//                           $all_dir[] = $this_entry;
//                      }
                 }
                 if (is_file("$directory_link$this_entry")) {
if ($DEBUGTEST==1) echo "VGR entry '$this_entry' is a file<BR>";
//                      if (isValidPictureFile("$directory_link$this_entry")) { // CHECK TEST
//if ($DEBUGTEST==1) echo "VGR entry '$this_entry' is valid picture file<BR>";
//                           $is_picture_directory=true;
//                      }
                 }    
            }
       }
$toto=@pclose($d_obj);
if ($DEBUGTEST==1) echo "VGR end of directories search, ".count($all_dir)." elements found.<BR>";
  } else {
       echo "Error!  Couldn't list directory $starting_directory for some reason!<br />";
       exit;
  }
?>

And it produced... WHAT I WAS EXPECTING :

VGR all_dir[] cleaned
VGR ok getdir of '.'
VGR entry 'aigle2' found
VGR entry 'aigle2' accepted as candidate
VGR entry 'aigle2' is a directory
VGR entry 'Babou' found
VGR entry 'Babou' accepted as candidate
VGR entry 'Babou' is a directory
VGR entry 'bebel' found
VGR entry 'bebel' accepted as candidate
VGR entry 'bebel' is a directory
VGR entry 'bedes' found
VGR entry 'bedes' accepted as candidate
VGR entry 'bedes' is a directory
VGR entry 'bin' found
VGR entry 'bin' accepted as candidate
VGR entry 'bin' is a directory
VGR entry 'blank.html' found
VGR entry 'blank.html' accepted as candidate
VGR entry 'blank.html' is a file
<snip>
VGR entry '' found
VGR end of directories search, 0 elements found. // that's normal, I commented out the filling in of $all_dir[]


IT WORKS !!!
0
 
LVL 15

Expert Comment

by:VGR
ID: 8142230
So My guess is that there are no files in your current ('.') directory...

Have you chdir()-ed ?
0
 

Author Comment

by:archker
ID: 8142364
there's alot of files in my current dir, 18 or so...

chkdir()-ed???? what?
0
 

Author Comment

by:archker
ID: 8142372
=)
you know what, I have my site on a unix platform...
0
 
LVL 15

Accepted Solution

by:
VGR earned 480 total points
ID: 8142450
I knew it 8-))
It could not have been anything else 8-)

STUPID BOTH OF US !!!

anyway, my technique should work fi you replace "dir /ON /B $directory2" by something like "ls -ltraH $directory2' (depending on your OS level)

try to get the command line with ls to list files and/or directories in the order you want, then substitute it to "dir /ON /B $directory2" and you are done 8-)
0
 

Author Comment

by:archker
ID: 8142476
$directory2 ...?
0
 
LVL 15

Expert Comment

by:VGR
ID: 8142496
it's the PHP variable.
Just put '.' for your testing purposes
0
 
LVL 15

Expert Comment

by:VGR
ID: 8142500
start with :
ls -ltra .

and expand from that with reading "man ls"
0
 

Author Comment

by:archker
ID: 8142505
...hihi...

IT WORKED!!!!!!!!!!!
changed it to: ls -t $starting_directory

thank you!
0
 
LVL 15

Expert Comment

by:VGR
ID: 8142530
Let me just say that if you had not answered "Alright, that worked somewhat good, but, maybe I should have been more specific" to my first posting with "DIR /OD", I would have understood that you were not on Windows :D

I think I merited my points on this one question :/
0
 
LVL 15

Expert Comment

by:VGR
ID: 8142537
just change this line and you are done :
$DEBUGTEST=0;
0
 

Author Comment

by:archker
ID: 8142802
hehe... well... thats life...
0
 

Author Comment

by:archker
ID: 8142809
thanks for not giving up =)
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question