PHP读取网络共享文件的文件内容 [英] Php read file contents of network share file

查看:336
本文介绍了PHP读取网络共享文件的文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来读取位于网络共享上的文件的文件内容.我可以使用共享主机的IP地址和共享文件夹到达该位置,但是我不知道执行该file_get_contents的正确命令和语法?开张?

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? fopen?

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

还是类似的东西?

更新* 尽管我知道该文件位于该确切目录中,但我也无法通过浏览器窗口访问该文件...

UPDATE* I also cannot access the file through a browser window although I know the file is located in that exact directory...

推荐答案

最好的方法(取决于您的需求)是简单地将其安装在本地计算机上,然后从安装中读取.这样就可以抽象出所有网络交互.

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.

因此,在Linux中:

So, in Linux:

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

然后,在php中,只需从挂载点访问它即可:

Then, in php, just access it from the mount point:

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

这篇关于PHP读取网络共享文件的文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆