Mapped Network Drives

最后都变了- 提交于 2019-11-27 08:11:26

问题


I have mapped a network drive to a computer in my home network. Now I am trying to access it via PHP - I did this quick test:

echo opendir('Z:\\');

This gives me:

Warning: opendir(Z:\) [function.opendir]: failed to open dir: No error in C:\wamp\www\webs\tester-function.php  on line 3

What have I done wrong here?

I don't want my users typing in the UNC path so is there a way to get the UNC path for them and maybe that will work when I try to access it? This is possible in Microsoft languages but I am not sure how to get PHP to do this - maybe using a cmd.exe command?

Please note, the mapped drive does exist as I can see it and I can access it. It also does not appear to be a permissions problem as I am assuming it would of complained about this IF it could access that drive...right?

Thanks all for any help


回答1:


The User Contributed Notes to opendir() have this:

I was trying to access network drives using this opendir function. I read so many posts saying that it was almost impossible to access a network drive and finally, I found the answer; there are 2 steps to be followed to access a network drive with PHP either on the same machine or another machine.

in this case, the user rights seemed indeed to be the problem, which can be different from your rights depending on what user PHP / the web server are running on.




回答2:


Open the Services MMC by going to Start -> Run (or by using the search box, if using Windows 7) and typing Services.msc and pressing enter. Find the Apache service. Having never used WAMP, I have no idea what it's been named. Hopefully it starts with the word "Apache" though, and thus shouldn't be too hard to find. Right-click on the service and select Properties. Switch to the Log On tab. Select the radio button next to "This account:" and enter in the credentials for the user account you want to run Apache under. If it's a network/domain account, use the "DOMAIN\user" syntax (or search for the account using the Browse button). Select OK and restart the Apache service. Verify that your changes worked by looking for the "httpd.exe" process in Task Manager and checking to see which user name the process is running under.

reference http://board.phpbuilder.com/board/showthread.php?t=10371870&page=2




回答3:


simple, use: "\\\\server\\dir\\subfolder" as the path. make sure you can access the "server".

works for me.
$arquivo = "\\\\server\\dir\\subfolder\\file.txt"; echo is_file($arquivo); //print 1.



来源:https://stackoverflow.com/questions/2592910/mapped-network-drives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!