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]

 




On Jan 22, 2007, at 10:20 PM, Chris wrote:

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/

Ok, I hope I can get this to work. The code
I copied here was code that was in the directory
reading loop, where I would have guess that
it would have the path info, but it did the same
thing. But I will take you suggestion.
Thanks for the reply;
JK

--
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