1

I need to open xml file in php page. The file is located in share folder that I made on my PC. File is accessible from other PC's that are connected to the server. How can I do that? Thank you!

Have tried this:

$file_read = file_get_contents('file:///10.8.8.89/test/20180716_BT-0444-0445.xml');
$file_read = preg_replace('/&/', ' and ', $file_read);
echo $file_read;

but code acts like the file doesn't exist. Before that I took xml files from the ftp server and it worked fine.

Vanfen
  • 131
  • 4
  • 13
  • try removing `file:///`, or the IP if it isn't being served up by apache or nginx – delboy1978uk Jul 17 '18 at 10:34
  • @delboy1978uk doesn't work :( – Vanfen Jul 17 '18 at 10:36
  • it should either be `file:///actual/path/to/file`, or `http://10.8.8.89/etc/etc`. Try both in the browser first – delboy1978uk Jul 17 '18 at 10:38
  • @delboy1978uk `file://10.8.8.89/test` works fine and opens the directory, but `http://10.8.8.89/test` doesn't open at all – Vanfen Jul 17 '18 at 10:56
  • that's bizarre. You don't have a folder with that ip as the name do you? :-P – delboy1978uk Jul 17 '18 at 10:59
  • @delboy1978uk I shared the folder so now I can type `\\10.8.8.89\test` in file explorer or browser and open it. It's now shared with all server users. And it has all the permissions for others to open it. – Vanfen Jul 17 '18 at 11:13
  • but it isn't going through a windowqs server? it's a network share? what is the full absolute path on your hard drive? – delboy1978uk Jul 17 '18 at 11:16
  • @delboy1978uk C:\test. It's a network share – Vanfen Jul 17 '18 at 12:01
  • ok, try `file://C:/test/20180716_BT-0444-0445.xml` – delboy1978uk Jul 17 '18 at 12:02
  • @delboy1978uk now it opens xml from ftp server. It should give error or smthng like this, but it opens xml, which needs to be open in previous site version... – Vanfen Jul 17 '18 at 12:15
  • i don't know what you mean – delboy1978uk Jul 17 '18 at 12:16
  • @delboy1978uk The idea of the site is to get the xml file from server and display it. On the page you have lots of buttons with numbers, so different button opens different xml. Now I need to get access to the archive folder and display xml files from there not using ftp, but somehow through the SMB. When I entered `file://C:/test/20180716_BT-0444-0445.xml` it was still opening files as if I was using ftp. – Vanfen Jul 17 '18 at 12:21
  • look up how to set headers in php to make it download instead of open ;-) – delboy1978uk Jul 17 '18 at 12:23
  • @delboy1978uk ok, thank you! – Vanfen Jul 17 '18 at 12:49
  • if it works let me know and i'll write a proper answer so other people can see it – delboy1978uk Jul 17 '18 at 13:21
  • @delboy1978uk I'll let u know if I'll find something :) – Vanfen Jul 17 '18 at 13:40
  • look here https://stackoverflow.com/questions/8485886/force-file-download-with-php-using-header – delboy1978uk Jul 17 '18 at 13:41
  • @delboy1978uk actually, I cant do that. It's not possible, because user doesnt need to download the file, site must open files in new tab and display them. – Vanfen Jul 18 '18 at 08:25
  • @delboy1978uk concept is: You click the button, file downloads to the folder on the website hosting and than website displays the file to user. As user quits, file deletes from the folder to empty the space. – Vanfen Jul 18 '18 at 08:27

1 Answers1

0

You can set the content type in the headers then the browser can correctly display xml

$file_read = file_get_contents('file:///10.8.8.89/test/20180716_BT-0444-0445.xml');

header('Content-Type: text/xml');
echo $file_read;
buildok
  • 785
  • 6
  • 7
  • I'd say that I have a problem with actually getting the file from share folder, but not with displaying it in browser. – Vanfen Jul 17 '18 at 11:59