List Info

Thread: note 70005 added to function.is-dir




note 70005 added to function.is-dir
user name
2006-09-29 13:42:16
The function is_dir will always return false if the handle
acquired with opendir is not from the current working
directory (getcwd); exception applies to "." and
"..". Thus, if you need a consistent dir listing
from any directory other than the current one, you must
change dir first. Example follows:
<?php
chdir( '..' );
$rep=opendir('.');
while (false != ($file = readdir($rep))){
  if (is_dir($file)){
    print("<a href='$file/'
class='text1'>$file</a>");
  }
}
?>
The above code will list all directories (with links) for
the ".." directory, relative to the current
working dir.

THE WRONG WAY TO DO IT FOLLOWS:
<?php
$rep=opendir('..');
while (false != ($file = readdir($rep))){
  //print "$file is here (may be a dir or
not)<br>";
  if (is_dir($file)){
    print "<a href='$file/'
class='text1'>$file</a><br>";
  }
}
?>
This code will turn into an empty list. If you want to make
sure, uncomment the commented line...
Regards...
----
Server IP: 200.185.126.100
Probable Submitter: 200.222.25.112 (proxied: 1.0 SPRLG01)
----
Manual Page -- http
://www.php.net/manual/en/function.is-dir.php
Edit        -- https://master
.php.net/note/edit/70005
Del: integrated  -- h
ttps://master.php.net/note/delete/70005/integrated
Del: useless     -- http
s://master.php.net/note/delete/70005/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/70005/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/70005/spam
Del: non-english -- 
https://master.php.net/note/delete/70005/non-english
Del: in docs     -- http
s://master.php.net/note/delete/70005/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/70005
Reject      -- https://mast
er.php.net/note/reject/70005
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )