Problem with Dir reading....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Problem with Dir reading....

Post by qads »

this script works fine, no problems with it at all

Code: Select all

<?
$root = "DIR"; 
if ($handle = opendir($root)) &#123; 
   while($file = readdir($handle)) &#123; 
    if ($file != "." && $file != ".." && $file != "this.txt") &#123; 
$file2 = substr("$file", 0, -4);
etc etc etc
balh balh balh
&#125; 
?>


it does't read "Update.txt" cos of

Code: Select all

if ($file != "." && $file != ".." && $file != "this.txt") &#123;
i have other files that i don't want it to read, is there any way i can stop it from reading files with .inc as ext?
that way i don't have to add more files every time i update.

thanks in adv
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

suggest

Code: Select all

$excludePostfixes = array('inc', 'php','pwd');
$excludeFiles = array('test.txt', '.htaccess');
...
if ($file != '..' && $file != '.')
&#123;
   $postfix = ($pos = strrpos( $filename, '.'))? strtolower(substr($filename, -($pos-1))) : FALSE;
  if ( ($postfix==FALSE || !in_array($filename, $excludePostfixes ) && !in_array($excludeFiles))
      ....display...
&#125;
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

where do i put that? :?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

come on guys, i really need help with this.....
Post Reply