Can't use dir() on site rootRSS

3 replies

Last post Feb 03, 2012 01:09 PM by HCamper

  • Can't use dir() on site root

    Jul 01, 2011 07:08 AM|geoffbeaumont|LINK

    I've run into an 'interesting' problem on my reseller hosting, which has both myself and my hosting provider stumped.

    The hosting is Win2k8r2 / IIS7.5 / PHP5.3 FastCGI, and in most respects works very well. However, I am using software (SugarCRM) which uses the PHP dir() function to examine directory contents within the website. This works fine in subdirectories but not on the site root. File permissions are currently read/write for the website user on all directories, and fopen() can get pointers to files in the site root.

    The following test script replicates the problem:

    <?php
    // Test in subdirectory
    echo '<p>Test in subdirectory:</p>';
    $dir = $_SERVER["DOCUMENT_ROOT"].'\soap';
    var_dump($dir);
    echo '<br/>';
    $f = fopen($dir . '\SoapData.php','r');
    var_dump($f);
    echo '<br/>';
    $d = dir($dir);
    var_dump($d);

    // Test in root directory
    echo '<p>Test in root directory:</p>';
    $dir = $_SERVER["DOCUMENT_ROOT"];
    var_dump($dir);
    echo '<br/>';
    $f = fopen($dir . '\index.php','r');
    var_dump($f);
    echo '<br/>';
    $d = dir($dir);
    var_dump($d);
    ?>

    The output of this script is:

     

    Test in subdirectory:

    string(65) "C:\HostingSpaces\<accountname>\<sitename>\wwwroot\soap"
    resource(2) of type (stream)
    object(Directory)#1 (2) { ["path"]=> string(65) "C:\HostingSpaces\<accountname>\<sitename>\wwwroot\soap" ["handle"]=> resource(3) of type (stream) }

    Test in root directory:

    string(60) "C:\HostingSpaces\<accountname>\<sitename>\wwwroot"
    resource(4) of type (stream)
    Warning: dir(C:\HostingSpaces\<accountname>\<sitename>\wwwroot,C:\HostingSpaces\<accountname>\<sitename>\wwwroot): Access is denied. (code: 5) in C:\HostingSpaces\<accountname>\<sitename>\wwwroot\test.php on line 21 Warning: dir(C:\HostingSpaces\<accountname>\<sitename>\wwwroot): failed to open dir: No such file or directory in C:\HostingSpaces\<accountname>\<sitename>\wwwroot\test.php on line 21 bool(false)

    As said, file system permissions are identical on both directories. My hosts can't find any PHP settings which could have this affect and I can't find anything which looks like it would do this - nor have I seen this behaviour before.

    Can anyone shed any light?

    TIA,

  • Re: Can't use dir() on site root

    Jul 01, 2011 11:01 AM|HCamper|LINK

    Hello,

    I ran the PHP script as dir_test.php from a test directory and this

    is the html decorated result:

    <?php
    // Test in subdirectory
    echo '<p>Test in subdirectory:</p>'
    ;
    $dir $_SERVER["DOCUMENT_ROOT"].'\soap'
    ;
    var_dump($dir
    );
    echo 
    '<br/>'
    ;
    $f fopen($dir '\SoapData.php','r'
    );
    var_dump($f
    );
    echo 
    '<br/>'
    ;
    $d dir($dir
    );
    var_dump($d
    );

    // Test in root directory
    echo '<p>Test in root directory:</p>'
    ;
    $dir $_SERVER["DOCUMENT_ROOT"
    ];
    var_dump($dir
    );
    echo 
    '<br/>'
    ;
    $f fopen($dir '\index.php','r'
    );
    var_dump($f
    );
    echo 
    '<br/>'
    ;
    $d dir($dir
    );
    var_dump($d
    );
    ?> 

    Results:

    <p>Test in subdirectory:</p>string(5) "\soap"
    <br/>bool(false)
    <br/>bool(false)
    <p>Test in root directory:</p>string(0) ""
    <br/>bool(false)
    <br/>bool(false)

    Above is results

    Could it be the SugarCRM has made changes to the php.ini settings?

    Martin

     

    Windows and Linux work Together IT-Pros
    Community Member Award 2011
  • Re: Can't use dir() on site root

    Jul 01, 2011 11:56 AM|geoffbeaumont|LINK

     Hi Martin,

     Thanks for trying it - you've posted the PHP code not the output by the way!

    SugarCRM doesn't (and can't - I don't have access to it) touch the php.ini, and isn't in any way invoked by the test script so can't make any runtime configuration changes - the test script was written to take SugarCRM out of the equation and make sure this was a pure IIS/PHP issue.

    I know the script should work, though - I can run it in other environments, just not this particular one!

  • Re: Can't use dir() on site root

    Feb 03, 2012 01:09 PM|HCamper|LINK

    Hi Geoff,

    Sorry for very late followup,

    BTW : Did you resolve the problems ?

    Regards,

    Martin


     

    Windows and Linux work Together IT-Pros
    Community Member Award 2011