[php] need help with readdir/opendir script

ej guys, it’s bin a long time iff bin back here… but i have a duecy of a problem for yuh right now… if tried this script in various ways but nothing seems to work… oh correction the script works… but the result i want does’nt come out… let me explain…

i’m creating FUSv1.0 (File Upload Script) the upload part works fine but i’m trying to create a whats uploaded area (readdir) but somehow i cant seem to get it to work correctly, im useing a template system and my gess is this is where the problem lays… the out come of my readdir script is 1… altough there are over 25 files…

this is how i use it:


$handle = opendir($upl_dir); 
while ( ($file=readdir($handle)) !== false ) { 
    if ( !is_dir($file) ){
		$list = $file."<br />";
		$tpl->assign("LIJST", "$list");
        } 
    }

can someone ecplain to me why this goes wrong or does someone have anotherway to do this?!

The code itself looks fine, but without knowing more about the template system you’re using I can only guess at what could be gowing wrong.

$tpl->assign(“LIJST”, “$list”);

My guess is that “assign” is overwritting the value each time it’s called. If there’s something like $tpl->append(“LIJST”, “$list”) where the new $list item gets appended on to a value then use that.

Otherwise try something like the following:

$list = "";
$handle = opendir($upl_dir);
while ( ($file=readdir($handle)) !== false ) {
  if ( !is_dir($file) ){
    $list .= $file."<br />";
  }
}
$tpl->assign("LIJST", "$list");

i have to thank you my man, it is so simple but it gave me a headake… thx dude… good job it works… check yuh PM to see the result…

Be careful of this:


if ( !is_dir($file) ){

In your example, it should probably read:


if ( !is_dir($upl_dir . $file) ){