1

I am using opendir and readdir to display a listing of available files on our fileshare server:

// defined in config.ini file:
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);

define('DRAWINGS_PATH', "\\\\Files\\shared\\Engineering\\Drawings\\");

$all_files = array();
if ($handle = opendir(DRAWINGS_PATH)) {
    while (($file = readdir($handle)) !== false) {
        $lc_file = strtolower($file);
        $dwg = strchr($lc_file, '.dwg');
        $pdf = strchr($lc_file, '.pdf');
        if (($dwg == '.dwg') || ($pdf == '.pdf')) {
            //$all_files[] = new HTMLForm_SelectOption('', $file);
            // I use the line above, but it's the same as the one below.
            $all_files[] = $file;
        }
    }
    closedir($handle);
}

When I test on my local PC, I see all of the files in that folder.

When I push this up to the server, it does not see anything.

This sounds to me like the local account, named Apache, does not have access to the network folder I need it to read from.

When I am remoted into the server, the local account that runs our web server appears to have access.

Apache screenshot

The only thing I see is that the user account on one PC says Apache and the username given permission on the folder is FILES\Apache and says Apache Web Server - but our network guy says these are the same accounts.

What else could I check?

[UPDATE] From php_info(): PHP Version 5.3.10

[UPDATE 2] Displayed info from config.ini file

[UPDATE 3]

Setting HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Re‌​strictNullSessAccess = 0 did not fix this.

I can remote login on the server using the Apache account, and view the files I need to get to:

screenshot of Apache logged in

However, when I attempt to get the Apache account to read these files so they can be displayed on a webpage, I get this error:

Warning: opendir(\Files\shared\Engineering\Drawings,\Files\shared\Engineering\Drawings): Access is denied. (code: 5) in C:...\FormView.php on line 183 Warning: opendir(\Files\shared\Engineering\Drawings): failed to open dir: No such file or directory

2 Answers2

2

Is PHP safe mode on? If so, you wouldn't be able to access an arbitrary path without first specifying it in the php.ini. Also, if you're not getting any errors when PHP Manual says you should, make sure error display isn't disabled - again in php.ini.

Lee S
  • 343
  • 1
  • 8
  • No, it shows `safe_mode = Off`. BTW, we are also running **PHP Version 5.3.10**, so Safe Mode is still in use. –  May 15 '14 at 15:58
  • 1
    opendir() at least, throws E_WARNING on error, which you're not outputting based on your snippet above. Try adding E_WARNING, E_NOTICE (or just output them all for a minute!), restart Apache and try again and see what errors are thrown. They should then point you in the direction of the trouble. – Lee S May 15 '14 at 16:10
  • So, it is an 'Access Denied' error, but it does not tell me who the user is that it is denied for. Obviously it must be Apache, but now I'm just stuck back with, "Why isn't this account accessing the folder?" –  May 15 '14 at 17:46
  • You might be interested in this link: http://stackoverflow.com/questions/1153824/php-access-network-path-under-windows It's old, but it may still be just as valid (I don't use Windows servers so I'm out of my league at this point...!) – Lee S May 15 '14 at 18:02
  • Setting `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\RestrictNullSessAccess = 0` doesn't seem to work just yet, but I'll see where it takes me. Thanks! –  May 15 '14 at 22:09
  • Keep us updated - it's an intriguing one, and someone else may have the same problem down the road. Sorry I can't help you further with Windows specifics but someone else may be along who has an answer :) The only thing I can add is, make sure you're setting that key on the file server, not the server where PHP is running. Might be obvious and done already, or might be a "ohhhhh!" moment. – Lee S May 16 '14 at 05:26
  • I will. I am currently on Update 3. If I can't get it, I'll add a bounty. That almost always gets an answer, but I can't do that until later. Stay tuned! :) –  May 16 '14 at 15:35
2

If you haven't solved this already... and with all due respect to your network guy, the user account Apache on DEV-WEB01 is (most likely) not the same as the user account Apache Web Server for FILESHARE01\Apache.

I would press your network guy to add the user Apache to FILESHARE01\Apache.

mseifert
  • 5,390
  • 9
  • 38
  • 100