Re: having trouble with is_file() and is_dir() on 5.1.2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



jekillen wrote:
Hello php developers:
I am having a problem with the following code:
OS: FreeBSD v6.0
Apache 1.3.34
php 5.1.2
-> $cont is an array produced from opening and reading a
directory:
for($i = 0; $i < count($cont); $i++)
     {
       print $cont[$i].'<br>';
        if(is_file($cont[$i]))
          {
             print "is file: ".$cont[$i].'<br>';
             //array_push($files, $cont[$i]);
            }
       else if(is_dir($cont[$i]))
            {
                print "is dir: ".$cont[$i]."<br>";
                 //array_push($dirs, $cont[$i]);
             }
      }


I'd be guessing it's a path issue.

Try prefixing the is_dir and is_file calls with the path to the directory they are in:

$basedir = '/whatever';

for($i = 0; $i < count($cont); $i++) {
  $fullpath = $basedir . '/' . $cont[$i];
  if (is_file($fullpath)) {
  .....
}

--
Postgresql & php tutorials
http://www.designmagick.com/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux