简体   繁体   English

PHP读取网络共享文件的文件内容

[英]Php read file contents of network share file

I'm looking for a way to read the file contents of a file located on a network share. 我正在寻找一种方法来读取位于网络共享上的文件的文件内容。 I can use the IP Address of the share host and the share folder to get to the location but I don't know the correct command and syntax to do that file_get_contents? 我可以使用共享主机的IP地址和共享文件夹到达该位置,但是我不知道执行该file_get_contents的正确命令和语法? fopen? 开张?

$text = fopen('//128.251.xxx.xxx/Common/sample.txt', 'r');

or something like that? 或类似的东西?

UPDATE* I also cannot access the file through a browser window although I know the file is located in that exact directory... UPDATE *我也无法通过浏览器窗口访问该文件,尽管我知道该文件位于该确切目录中...

The best way (depending on your needs) is to simply mount it on your local machine, and then read from the mount. 最好的方法(取决于您的需求)是将其简单地安装在本地计算机上,然后从安装中读取。 That lets all the network interaction be abstracted away. 这样就可以抽象出所有网络交互。

So, in Linux: 因此,在Linux中:

mount -t cifs //192.168.XXX.XXX/share /path/to/mount -o user=username,password=password

Then, in php, just access it from the mount point: 然后,在php中,只需从挂载点进行访问即可:

$data = file_get_contents('/path/to/mount/path/to/file.txt');

According to PHP Filesystem manual UNC/SMB files should be accessible. 根据PHP Filesystem手册,应该可以访问UNC / SMB文件。 Try the following: 请尝试以下操作:

\\server\share\file.txt

It may be one of those cases where the // may be mistook as a reference to the root directory. //可能误将//作为对根目录的引用。 And given this is an SMB path, I would use the traditional backslashes. 鉴于这是SMB路径,我将使用传统的反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM