-1

I need php to detect folder names in a directory on my computer not in the project directory in wamp server. i tried all the answers on Using scandir() to find folders in a directory (PHP) but it didn't work it says the directory is not on the project directory when i tested scandir as in this code:

$path = 'extracted/' . $name[0];
$results = scandir($path);

foreach ($results as $result) {
    if ($result === '.' or $result === '..') continue;

    if (is_dir($path . '/' . $result)) {
        //code to use if directory
    }
}

I am trying this also but i got empty array

$path = 'D:\tests\Ed';
$folders=glob("{$path}/*");
 print_r($folders);
Community
  • 1
  • 1
user3052503
  • 35
  • 2
  • 12
  • use `is_dir()`, documentation [here](http://php.net/manual/en/function.is-dir.php) – Xorifelse Jun 13 '16 at 15:52
  • Remember the user account under which your webserver is running needs (ntfs-security-read-)access on the folder(s) in question. – dognose Jun 13 '16 at 15:54
  • Where is the code you tried? Copy paste it, attaching a link and not writing the gist is not good – Aminah Nuraini Jun 13 '16 at 16:03
  • is_dir didn't help me @Xorifelse i've read the documentation and tried some code but i got nothing – user3052503 Jun 13 '16 at 16:23
  • what do you mean (ntfs-security-read-) @dognose how to use it? – user3052503 Jun 13 '16 at 16:24
  • i just added some code i tried @Aminah Nuraini – user3052503 Jun 13 '16 at 16:25
  • 1
    See here for Security-Permission Configuration: http://www.ntfs.com/ntfs-permissions-setting.htm It has nothing to do with PHP, it's a windows feature - but obviously windows needs to grant read-permissions to your webserver, so you can "read" the directory. To test, whether this is your issue or not, ensure that "Everyone" has at least Read/List Folder Content-permissions. (If its working then, figure out the user you are running your webserver with, remove everyone again and setup proper permissions) – dognose Jun 13 '16 at 16:37
  • @Xorifelse include path has nothing to do with this. Include-path only specifies where php is looking for files in the first-place. Absolute Paths are still absolute paths. – dognose Jun 13 '16 at 16:45
  • @dognose Quite correct, sorry I meant [open_basedir](http://php.net/manual/en/ini.core.php#ini.open-basedir). The problem is that PHP refuses to do anything with files outside the root directory, but you would be able to add the folder to the include path and run a script from there. – Xorifelse Jun 13 '16 at 16:53
  • 1
    @Xorifelse if the environment is configured accordingly, PHP can open anything, no matter the directory. – dognose Jun 13 '16 at 17:00
  • 1
    (open_basedir can be used to restrict access to certain folders, by default everything is allowed - Maybe that's different for the WAMP-Package. Also I think this just affects the execution of script files - not overall file-access.) – dognose Jun 13 '16 at 17:06

1 Answers1

0

the only way i could run the code is by putting the folder in the project directory ,

$path = 'C:\wamp\www\my project php\ED';

but is there another way?

user3052503
  • 35
  • 2
  • 12
  • 1
    I suspect this is an apache issue and not a PHP issue. Try running your script via the CLI. It will work fine. To give apache access to anywhere then you need to setup a `virtual host`. maybe interesting? https://www.virendrachandak.com/techtalk/creating-multiple-virtual-websites-in-wampserver/. I use XAMPP on windows and had similar issues. It makes sense from a security viewpoint. – Ryan Vincent Jun 13 '16 at 22:11
  • Thanks @Ryan Vincent it was interesting topic. – user3052503 Jun 13 '16 at 22:44