dongtangxi1584 2012-03-26 02:46
浏览 50
已采纳

使用PHP5.2 + IIS7.5访问网络共享

I'm using php 5.2 with IIS7.5.

I have a network share on a NAS that is username and password protected. I cannot disable or change authentication info on the NAS. I need to be able to access that network share via php.

I've done the following:

Created new user in windows whose username and password matches those on the NAS. Created IIS application pool that uses this same auth info. Created a web.config file inside of the php app directory with an impersonation turned on, using the same auth info.

identity impersonate="true" password="ThePass" userName="TheUser" />

Turned on ASP.NET impersonation in the application authentication in IIS.

None of this seemed to work with this simple line of code in php:

$dir = opendir("\\someservername\somesharename"); Warning: opendir(\someservername\somesharename) [function.opendir]: failed to open dir: No error in C:\websites\site\forum\testing.php on line 7

So, I decided to test the configuration with ASP.NET.

string[] diretories = System.IO.Directory.GetDirectories("\\someservername\somesharename"); The asp.net test worked perfectly.

Going further down the rabbit hole, I ran phpinfo() and checked the username info in it. Down in the "Environment" section of phpinfo, I found the "USERNAME" item. Its value was "TheUser," as was what I expected.

Everything points to the system being configured correctly until I tried:

echo get_current_user(); Which returned, "IUSR." That surely isn't what I expected.

So, how in the world do I get php + IIS7.5 to read from a foreign network share?

Update:

Thanks to a few of the answers, I've added

$result = shell_exec("net use o: \\\\pathToServer\\27301  /persistent:yes 2>&1");

Which returns a success. I'm still getting the error on opendir. I tried another test and used is_dir. This returned false on my newly created mapped drive.

var_dump(is_dir("o:\\"));

// Prints: bool(false) 

UPDATE

I ran the script from the command line when logged in as the user that created. The scripts executes correctly. Could this take us back to get_current_user() which returns IUSR? I tryied getmypid() which returned a process ID. I cross referred that process id with the task manager and found that it was for php-cgi.exe, running under the custom user account that I made.

  • 写回答

3条回答 默认 最新

  • dongxiang5879 2012-04-02 19:52
    关注

    You can try a test by mapping it like

    $command = "net use $drive \"\\\\$ip\\$share\" $smb_password /user:$domain\\$smb_username";
    $result = shell_exec($command);
    

    on opendir you need to have \\\\$server_name\\$share try with 4 '\' and if mapping like that works and 4 '\' is failing on opendir. You may have credentials not matching.

    If you map it this way new user you created in windows whose username and password matches those on the NAS will have rights on mapped drive that way you do not need to worry about the scope.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效