Page 1 of 1

Problem with Dir reading....

Posted: Fri Jun 14, 2002 7:31 pm
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

Posted: Sat Jun 15, 2002 3:50 am
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;

Posted: Sat Jun 15, 2002 8:52 am
by qads
where do i put that? :?

Posted: Sat Jun 15, 2002 6:09 pm
by qads
come on guys, i really need help with this.....