Php reads the contents of a network file

I am looking for a way to read the contents of a file located on a network share. I can use the IP address of the shared host and the shared folder to get to the location, but I don’t know the correct command and syntax for this get_contents file? Eorep?

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

or something like that?

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

+6
file php
source share
2 answers

The best way (depending on your needs) is to simply install it on the local machine and then read it from the mount. This allows you to abstract from all network interactions.

So on 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'); 
+7
source share

According to the PHP file system manual, UNC / SMB files must be available. Try the following:

 \\server\share\file.txt 

This may be one of those cases where // can be taken as a link to the root directory. And given that this is the SMB path, I would use traditional backslashes.

+4
source share

All Articles