使用 PHP 访问 Windows 共享
我需要使用 PHP 访问 Windows 共享上的 Excel 文件,但似乎遇到了身份验证问题。
我正在使用 PHP-ExcelReader 打开并读取该文件。在我的本地计算机上运行良好,但我放置它的服务器无权访问此共享,因此它告诉我该路径不可读!
我什至不确定访问此共享的路径是否正确:
$file_to_include = "\\\\10.9.8.7\depts$\ExcelFile.xls";
但正如我所说,它可以在我的计算机上运行,所以我对此感到满意。
有什么方法可以在此处添加我的凭据吗?
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.
I'm using PHP-ExcelReader to 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!
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于 PHP 不支持 SMB,因此客户端必须可以在本地访问路径
\\10.9.8.7\depts$\ExcelFile.xls
。编辑:至少不是原生的,尝试smb4php
Path
\\10.9.8.7\depts$\ExcelFile.xls
must be locally accessible to the client, since PHP has no SMB support.EDIT: At least not natively, try smb4php
你的道路是正确的。
您可以尝试的一件事是在服务器上共享驱动器,然后将共享驱动器映射到每个用户计算机上(确保它们都是相同的驱动器号或名称),或者只是您的计算机上。如果不是太多,用户计算机会更好,以防您外出或忘记进行身份验证。这样,当用户进行身份验证时,它就会打开驱动器。然后您可以通过以下方式调用驱动器:
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:
您的路径是正确的,但请记住,当使用双引号时, $ amd 反斜杠是 php 中的特殊字符。
所以你可以写:
或者你使用双引号,但在特殊符号之前添加一个额外的反斜杠
,或者你必须使用正斜杠作为目录分隔符,但美元仍然必须转义
关于authdata:如果你正在运行一个php文件,它通常继承启动进程的权限。
这意味着,如果您已经在资源管理器中保存了此共享的身份验证并且正在启动 php,则该 php 文件将继承此已保存的权限。
但不要忘记,当您在网络服务器中运行 php 时,该网络服务器可能在不同的用户中运行,该用户与您当前登录的用户不具有相同的权限。
You path is correct, but keep in mind, that $ amd backslash is a special-char in php when using double quotes.
So you could either write:
or you use double quotes but you add a extra backslash before the special signs
or you yust use forward slashes as directory separator, but the dollar still must be escaped
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.
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.