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 Tue, January 23, 2007 12:03 am, 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]);
>               }
>        }
>
> The print statements produce the following:
>
> collections
> groups
> in
> index.php
> lists.php
> new_multi.php
> new_single.php
> out
> pref_code
> pref_funct.php
> process.php
> requests
> rlists
> routing.php
> send.php
> steps.php
> store
> templates
>
> is dir: templates  <- only directory recognized (extra line breaks
> added here for readability)
>
> usr_config.php
> usr_pref.php
>
> everything without an extension is a directory
> You will notice that the only directory detected
> by this code is templates. There are no files
> detected by this code. Does this have something
> to do with stat cache? I want to make one array
> with directories and one array with files. I can't
> see any syntax or logic problems.
> Thanks in advance;

is_file and is_dir are checking in the same dir as your PHP script,
not the one you opened.

So you are detecting that your PHP dir *also* happens to have a
directory named "templates" which is a mere coincidence to the fact
that the directory you opened had a directory named "templates"

Use a FULL PATH when you are messing with files/dirs if at all
possible, and your life will be much simpler.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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