Php read file contents of network share file

寵の児 提交于 2019-11-27 08:58:35

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:

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:

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

According to PHP Filesystem manual UNC/SMB files should be accessible. 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.

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