filtype() Problems

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I wrote a simple script utilizing readdir() to read the contents of a  
directory, then of all subdirectories and thier contents and echo the  
filenames to the page.

But, here is the problem. I'm also echo'ing filtype() to ensure only  
files and not the directory names are printed. But I've noticed some of  
the files are not returning a type.

Has anyone seen this before? Am I just crazy?

Thanks for your help,


UPDATE: filtype() Problems

The files in question do give a filetype() and a '1' for file_exists()  
if I move them to the top level directory, but not when in the sub  
directory. Again, this only happens with some files. Others return valid  
types and '1's.

Is there a reason why I wouldn't be able to get filetype from some files  
in a directpory but not others? The permissions appear to be all correct  
and this happens on Windows IIS and Apache.

I'm at a loss... attached is the part of the script in question.

for ($i=0; $i < count($dirnames); $i++)
        echo "<br/>";
        echo $dirnames[$i] . "<br/>";
        echo filetype($subnames[$dirnames[$i]][0]) . "<br>";
    for ($b=0; $b < count($subnames[$dirnames[$i]], COUNT_RECURSIVE); $b++)
    if (filetype($subnames[$dirnames[$i]][$b])=='file')
        {                                            echo filetype($subnames[$dirnames[$i]][$b]) . "                 - " .  
$subnames[$dirnames[$i]][$b] . "<br/>";

Kevin Cloutier wrote:    
Quoted text here. Click to load it

Re: filtype() Problems

Are you not getting anything in return for the files that do not
produce a type?

Quoted text here. Click to load it
"Returns FALSE if an error occurs. filetype() will also produce an
E_NOTICE message if the stat call fails or if the file type is

Set your error reporting for the script to report all errors to try an
pinpoint what is happening. It is hard to tell not seeing the rest of
the script and your filesystem.

Re: filtype() Problems

Also you can try to use is_dir() to see if you have a file or
directory. Sorry just thought of that.

Re: filtype() Problems

Hi Jeff,

Thanks for the help. For now I have found a work around. For some reason  
this is only effecting some of the files and not any directories. So,  
instead of using filetyp()=='file' it dawned on me to use !='dir'. That  
seems to work fine for my needs.

But you're right about error messaging, as you can tell I'm still new at  
this so I will have to investigate turning this on today.

With that said, this is completely baffling. For the files that don't  
produce a type I don't see anything printed to the screen. Maybe a NULL  
value is returned? I wonder if I can check that? But it gets stranger.

At first I thought it was a problem with my for loop. But if I "copy"  
the files that do give a type, and place the copies in the same  
directory (i.e. "file.txt" copied to "copy_file.txt"), they DO give a  
type. So it's not the loop.

I've tried this on a Mac, Windows IIS and Linux, so strange. But I'll  
see what I find in the error logs.

Again, thanks for the help,


Jeff Johns wrote:
Quoted text here. Click to load it

Site Timeline