Status
Not open for further replies.
Here's a weird one..

PHP appears that it can read file types and sizez just fine if you're readin the files in the same directory the script is in.. but if you're running the script in one folder, and reading files in another folder it doesn't work.

I run the script in one folder, and try to get file data for a file in another folder and it won't work. it will display the file name, but all of the following functions i have tried don't do anything at all (not even report the file as unknown): is_file, file_exists, is_readable, filetype, filesize, lstat etc..

any idea's? why would this be?

it's php4.0 runnin on linux, any help would be GREATLY appreciated :)
 

theFinn

Ars Tribunus Militum
2,705
Subscriptor++
I've found that PHP tends to be picky about getting the full path when using the file info functions. For example it won't work if the path you give it is ../myfile.jpg, but it will work if you give it /home/bob/myfile.jpg

If you can't use the full path then it will also work if you move into the directory you want to read files from first, i.e. use a chdir('../mystuff/');

Good luck :)

- theFinn
 
i apologize for not making myself clear on that part of it. I have tried the full path. i've attempted to chdir but i get some kind of error cause it's in a loop.. hmm.. okay the best way to explain.

okay. see what i'm trying to do here is open one directory and read it's entire size by traversing through all the files and sub-directory's. here is my code below - if you can point out my mistakes here or suggest a better way of approaching it please?

(if you're going to test this - make sure the sub-directory that the script is reading has files other than just html and txt, like images or something)

code:<HR>
Code:
<?php<P>function makeArray($directory)
{
    $mydir = opendir("$directory");
    while($entry = readdir($mydir))
    {
        $myarray[] = "$entry";
    }
    $garbage1 = array_shift($myarray);
    $garbage2 = array_shift($myarray);
    checkArray($myarray);
}<P>function checkArray($array)
{
    foreach($array as $key=>$value)
    {
        if(is_file("$value"))
        {
            print(filetype("$value") . " - $value (" . filesize("$value") . " bytes)
\n");
        }
        elseif(is_dir("$value"))
        {
            print(filetype("$value") . " - $value (" . filesize("$value") . " bytes)
\n");
            $value = makeArray($value);
        }
        else
        {
            print(filetype("$value") . " - $value (" . filesize("$value") . " bytes)
\n");
        }
    }
}<P>$maindir = ".";
makeArray($maindir);<P>?>
 
Status
Not open for further replies.