php - php - 无法从字符串解析 XML - Laravel 存储
问题描述
我正在为 Laravel 使用Orchestra/解析器。我已经安装了它,就像文档说的那样,我正在尝试使用它来读取我的服务器上可用的 XML 文件。我有一个 FTP 服务器,自动报告正在发送到该服务器。我需要将文件从我的 FTP 服务器下载到我的公共磁盘:
//Search for the files.
$fileName = array_filter(Storage::disk('ftp')->files("/reports"), function ($file)
{
//This get filename from the FTP server (/reports folder), that includes the current date (YYYY-MM-DD) in the file name.
return preg_match('/'.date("Y", time()).'\-'.date("m", time()).'\-'.date("d", time()).'(.*)\.[a-zA-Z]{3}/m', $file);
});
我可以使用上面的代码在我的 FTP 服务器上找到文件。有用。
接下来,我将文件从我的 FTP 服务器移动到我的公共服务器:
//Set the new filename. We use this later on, when we move the file.
$new_fileName = "milestone_report_".date("Y-m-d", time()).".xml";
//$fileName[0] already includes the /reports path.
$move_file = Storage::disk("public")->put("/reports/".$new_fileName."", Storage::disk('ftp')->get($fileName[0]));
这也有效。最后我需要能够读取/获取 .xml 文件的内容,使用XmlParser
. 我确实喜欢文档中的描述:
//Load the new file, so we can use it with the "xml parser package"
$xml = XmlParser::load("/storage/app/public/reports/".$new_fileName."");
但是,上面给了我以下错误:
无法从字符串解析 XML。
- 我已经验证 XML 文件确实位于我在 Laravel 的存储文件夹中。/存储/应用程序/公共/报告
更新:
我试图从我的公共文件夹中加载一个 XML 文件www.domain.com/xmlfile.xml
,这就像它应该的那样工作!
如何使用 XmlParser 从我的存储中加载?
-
-
解决方案
所以我想出了这个。XmlParser::load()
我没有使用该函数,而是使用了该函数,并使用如下方式XmlParser::extract()
提取了文件:Storage::disk()
$xml = XmlParser::extract(Storage::disk('public')->get("/reports/".$new_fileName.""));
它给我错误“无法从字符串解析 XML”的原因是因为以前我只获取到我的 XML 文件的路径(这只是一个字符串)。XmlParser
需要将文件直接加载到方法中。
推荐阅读
- clojure - Clojure - 创建一个无除数函数
- rest - 尝试将时间戳作为请求参数发送到我的 REST API 时收到 400
- php - Wordpress 检查 slug 的任何部分是否存在
- ruby-on-rails - Bundler:您必须使用 Bundler 2 或更高版本与此锁定文件
- c# - How do I Install OpenIDConnect Nuget Package with Dependency on "DNX 4.5.1"
- c# - .net core 2.1 reusing _Layout throughout various projects
- node.js - 使用 Dialogflow Conv.Data 或 Conv.User.Storage 的简单计数器
- c++ - Cachegrind:为什么有这么多缓存未命中?
- python - 如何在 gobject 应用程序指示器图标上将数字显示为超级脚本?
- regex - symfony4 中的正则表达式