# \[php\] need help with readdir/opendir script

**URL:** https://forum.kirupa.com/t/php-need-help-with-readdir-opendir-script/184612
**Category:** Uncategorized
**Created:** [April 6, 2006, 9:33am UTC](https://forum.kirupa.com/t/php-need-help-with-readdir-opendir-script/184612 "2006-04-06T09:33:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sWo0p](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sWo0p](https://forum.kirupa.com/u/sWo0p)
#### Post date: [April 6, 2006, 9:33am UTC](https://forum.kirupa.com/t/php-need-help-with-readdir-opendir-script/184612/1 "2006-04-06T09:33:39Z")

</div>

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:

```php

$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?!

---

<div class="post-metadata">

### Author: ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)
#### Post date: [April 6, 2006, 5:31pm UTC](https://forum.kirupa.com/t/php-need-help-with-readdir-opendir-script/184612/2 "2006-04-06T17:31:27Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![sWo0p](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sWo0p](https://forum.kirupa.com/u/sWo0p)
#### Post date: [April 6, 2006, 7:21pm UTC](https://forum.kirupa.com/t/php-need-help-with-readdir-opendir-script/184612/3 "2006-04-06T19:21:35Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![ironikart](https://avatars.discourse-cdn.com/v4/letter/i/7feea3/32.png) [@ironikart](https://forum.kirupa.com/u/ironikart)
#### Post date: [April 6, 2006, 10:09pm UTC](https://forum.kirupa.com/t/php-need-help-with-readdir-opendir-script/184612/4 "2006-04-06T22:09:40Z")

</div>

Be careful of this:

```php

if ( !is_dir($file) ){

```

In your example, it should probably read:

```php

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

```
