PHP open_basedir with UNC path

2019-07-29 05:27发布

Running PHP 5.3.1 on a Windows server, I have to modify a PHP script to access XML files on a network share. For various reasons the files cannot be placed on the PHP server, and I am not allowed to create a mapped drive on the PHP server so I have to modify the open_basedir parameter in PHP.ini to include the UNC path to the share, e.g.:

open_basedir = "E:\inetpub\;E:\DB_HubDataFiles\;\\stdmfps01\inter-departements$\CVSC-CDT-Estimation-Cedule\"

However when I try to access files on the share I get the "open_basedir restriction in effect" error. I am trying to access the files as follows:

$jobfilename = "//stdmfps01/inter-departements$/CVSC-CDT-Estimation-Cedule/" .$job . ".xml";
if (file_exists($jobfilename)) {
    $jobxml = simplexml_load_file($jobfilename);
    etc...

I have been assured that it is not a problem of rights, and anyway the error indicates a problem with open_basedir. So my questions are:

  1. does open_basedir handle UNC paths under Windows (I have seen conflicting statements about this)?
  2. if so is there some problem with my syntax?
  3. do I have other options than using open_basedir?

Thanks.

标签: php
2条回答
闹够了就滚
2楼-- · 2019-07-29 05:49

This worked for me: Replace the backslashes with slashes

open_basedir = "E:\inetpub\;E:\DB_HubDataFiles\;//stdmfps01/inter-departements$/CVSC-CDT-Estimation-Cedule/"
查看更多
手持菜刀,她持情操
3楼-- · 2019-07-29 05:59

Anyway, here's what ended up working for me, even if I am not totally clear why:

In php.ini changed the open_basedir parameter to use the IP address instead of the server name, and used the parent directory of the directory where my files are located, instead of the directory itself:

\\\nnn.nnn.nnn.nnn\inter-departements$\

instead of:

 \\servername\inter-departements$\CVSC-CDT-Estimation-Cedule\

In the PHP script used the IP address as well:

$jobfile = "//nnn.nnn.nnn.nnn/inter-departements$/CVSC-CDT-Estimation-Cedule/" . ($jobid) . ".xml";
查看更多
登录 后发表回答