2

I am going crazy with this one

I have this folders and files structure

  • /
    • /projects
      • /mytest
        • /install
          • /index.php
        • /product
    • /resources

So, inside my install/index.php file I am trying to verify if /product folder does exist. I know that the folder exists, but looks like PHP doesn't. My code:

if(file_exists('../../mytest/product') && is_dir('../../mytest/product')) {
    echo 'Folder exists!';
} else {
    echo 'PHP is blind or something!';
}

Maybe I am very tired, but I just cannot figure out what is wrong. Some rested minds here maybe will see the problem. Thanks!

6
  • 1
    What do getcwd() return? Commented Jun 4, 2012 at 22:39
  • Debug with realpath('../../mytest/product'); Commented Jun 4, 2012 at 22:39
  • 1
    Don't forget about directory permissions. PHP may simply not see that directory. Commented Jun 4, 2012 at 22:40
  • Run clearstatcache() since the result of these functions are stored in the stat cache. Commented Jun 4, 2012 at 22:41
  • Are you running this php file locally or as an http request? The latter can mess with how the directories are viewed, and how permissions are read. Commented Jun 4, 2012 at 22:45

1 Answer 1

1

With your current directory structure:

/
    /projects
        /mytest
            /install
                /index.php
            /product
    /resources

The following code works just fine:

<?php
if(file_exists('../product') && is_dir('../product')) {
    echo 'Folder exists!';
} else {
    echo 'PHP is blind or something!';
}
?>

As does your current code:

<?php
if(file_exists('../../mytest/product') && is_dir('../../mytest/product')) {
    echo 'Folder exists!';
} else {
    echo 'PHP is blind or something!';
}
?>

Both solutions outputted "Folder exists!", so the issue is related with folder permissions.


You need to confirm:

  • Owner for that folder

Remember that the owner of the directory has to be the same of the script user, otherwise this function will always return false when PHP is running in safe_mode..

Limit the files that can be opened by PHP to the specified directory-tree..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.