Search code examples
symfonyconfigscandir

Scandir() with getParameter Symfony 2


i'm using Wampserver2.2, Symfony 2.5 and Php 5.3.13 and i create a file explorer.

To scan my directory i actually do in my showAction() in my DefaultController :

And it works great !

$dir = \\\\servername\Dossiers Projet\Path\to\Directory
$clients = scandir($dir);

I want to parameter the path directory so in my config.yml :

parameters:
    chemin_clients: \\\\servername\Dossier Projets\Path\to\Directory

i've also test :

parameters:
    chemin_clients: '\\\\servername\Dossier Projets\Path\to\Directory'

And the new showAction() :

$dir = $this->container->getParameter('chemin_clients');
$clients = scandir($dir);
var_dump($clients);

var_dump($dir); return string '\\\\servername\Dossier Projets\Path\to\Directory'

var_dump($clients); return boolean FALSE

Warning: scandir(\\servername\Dossiers Projet\Path\to\Directory) [function.scandir]: failed to open dir: No such file or directory in

I dont know what's the problem.. Thanks a lot!


Solution

  • The scandir() (and opendir() as well) function returns FALSE on failure - if directory is not a directory resource, then boolean FALSE is returned. The problem is caused by tha fact, that Apache service on Windows has limited access to network resources, such as shares and pipes, because it has no credentials and must connect using a null session - so the \\\\servername\Dossier Projets\Path\to\Directory path is not a valid directory resource for PHP processed by the Apache service.

    You can set the NullSessionPipes and NullSessionShares values, which are used to specify the pipes and shares to which null sessions may connect in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters registry key, or you can add the REG_DWORD value RestrictNullSessAccess=0 to that key to allow all null sessions to access all pipes and shares created on that machine (but consider the risks, of course).