【问题标题】:Displaying files from the share folder by using php (Google Chrome)使用 php (Google Chrome) 显示共享文件夹中的文件
【发布时间】:2018-07-17 10:31:27
【问题描述】:

我需要在 php 页面中打开 xml 文件。该文件位于我在 PC 上创建的共享文件夹中。可以从连接到服务器的其他 PC 访问文件。我怎样才能做到这一点? 谢谢!

试过这个:

$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;

但代码的行为就像文件不存在一样。 在此之前,我从 ftp 服务器获取 xml 文件,它运行良好。

【问题讨论】:

  • 尝试删除file:///,如果 apache 或 nginx 没有提供 IP,请尝试删除该 IP
  • @delboy1978uk 不起作用 :(
  • 它应该是file:///actual/path/to/filehttp://10.8.8.89/etc/etc。首先在浏览器中尝试两者
  • @delboy1978uk file://10.8.8.89/test 工作正常并打开目录,但 http://10.8.8.89/test 根本打不开
  • 这很奇怪。您没有以该 ip 作为名称的文件夹吗? :-P

标签: php xml file-get-contents smb file-sharing


【解决方案1】:

您可以在标题中设置内容类型 那么浏览器就可以正确显示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;

【讨论】:

  • 我会说我在实际从共享文件夹中获取文件时遇到了问题,但在浏览器中显示时却没有。
猜你喜欢
  • 2021-12-30
  • 1970-01-01
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多