使用 PHP 访问 Windows 共享
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1444976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing a Windows Share using PHP
提问by Ciaran
I need to access an Excel file on a Windows Share using PHP but seem to be running into what looks like an authentication issue.
我需要使用 PHP 访问 Windows 共享上的 Excel 文件,但似乎遇到了身份验证问题。
I'm using PHP-ExcelReaderto open and read the file. Works fine on my local machine but the server I'm putting it on doesn't have the rights to access this share, and so its telling me that the path is unreadable!
我正在使用PHP-ExcelReader打开和读取文件。在我的本地机器上运行良好,但我放置它的服务器无权访问此共享,因此它告诉我路径不可读!
I'm not even sure the path I have for accessing this share is correct:
我什至不确定我访问此共享的路径是否正确:
$file_to_include = "\\10.9.8.7\depts$\ExcelFile.xls";
But it works on my machine, as I said so I'm happy with that.
但正如我所说,它适用于我的机器,所以我对此很满意。
Is there any way I can add my credentials in here somewhere?
有什么办法可以在此处的某个地方添加我的凭据?
采纳答案by Cem Kalyoncu
回答by stormdrain
Your path is correct.
你的路径是正确的。
One thing you could try is to share the drive on the server, then map the shared drive on each users computer (make sure they are all the same drive letter, or name), or just your computer. If it's not too many, the users computers would be better, in case you're out, or forget to authenticate. This way, when the user authenticates, it opens the drive up. You can then call the drive via something like:
您可以尝试的一件事是在服务器上共享驱动器,然后在每个用户的计算机上映射共享驱动器(确保它们的驱动器号或名称都相同),或者只是您的计算机。如果不是太多,用户的计算机会更好,以防您外出或忘记进行身份验证。这样,当用户进行身份验证时,它会打开驱动器。然后,您可以通过以下方式调用驱动器:
$file_to_include = '\\'.$_SERVER['REMOTE_ADDR'].'\mappedDrive\file.xls';
回答by Radon8472
You path is correct, but keep in mind, that $ amd backslash is a special-char in php when using double quotes.
您的路径是正确的,但请记住,当使用双引号时,$ amd 反斜杠是 php 中的特殊字符。
So you could either write:
所以你可以写:
$file_to_include = '\10.9.8.7\depts$\ExcelFile.xls';
or you use double quotes but you add a extra backslash before the special signs
或者您使用双引号,但在特殊符号前添加了一个额外的反斜杠
$file_to_include = "\\10.9.8.7\depts\$\ExcelFile.xls";
or you yust use forward slashes as directory separator, but the dollar still must be escaped
或者您只能使用正斜杠作为目录分隔符,但仍然必须转义美元
$file_to_include = "\\10.9.8.7/depts/$/ExcelFile.xls";
About the authdata: if you are running a php file, it usually inherits the permissions of the starting process. What means, if you already saved the auth for this share in your explorer and you are starting a php, the php file inherits this already saved permissions.
关于authdata:如果你运行的是php文件,它通常会继承启动进程的权限。这意味着,如果您已经在资源管理器中保存了此共享的身份验证,并且您正在启动 php,则 php 文件将继承此已保存的权限。
But dont forget, when you run a php in a webserver, this webserver is maybe running in a different user, which dont has the same permissions like your currently logged in user.
但是不要忘记,当您在网络服务器中运行 php 时,该网络服务器可能正在不同的用户中运行,该用户与您当前登录的用户具有不同的权限。

