【发布时间】:2018-03-18 12:59:23
【问题描述】:
我正在尝试在我的 php7 laravel 项目中使用数字海洋空间。该代码非常简单,只需加载文件并将其复制到目录即可。在我的本地机器上一切正常,但在我的数字海洋服务器上失败并出现此错误
找不到类“SimpleXMLElement”
即使在数字海洋服务器上,如果我使用 tinker 运行相同的存储命令,它也可以正常工作。可能是什么问题?
我的get_loaded_extensions() 返回
get_loaded_extensions()
[
"Core",
"date",
"libxml",
"openssl",
"pcre",
"zlib",
"filter",
"hash",
"pcntl",
"Reflection",
"SPL",
"session",
"standard",
"mysqlnd",
"PDO",
"xml",
"apcu",
"calendar",
"ctype",
"curl",
"dom",
"mbstring",
"fileinfo",
"ftp",
"gd",
"gettext",
"iconv",
"json",
"exif",
"mysqli",
"pdo_mysql",
"Phar",
"posix",
"readline",
"shmop",
"SimpleXML",
"sockets",
"sysvmsg",
"sysvsem",
"sysvshm",
"tokenizer",
"wddx",
"xmlreader",
"xmlrpc",
"xmlwriter",
"xsl",
"zip",
"Zend OPcache",
]
所以看起来 xml 和 simplexml 已安装。正如link、php-xml 和php-simplexml 所建议的,应该安装。我需要单独安装一些东西吗?
另外,我的文件上传代码是这样的
public function uploadNew($file, $title, User $user)
{
if (!File::directoryExists($user->username)) {
Storage::makeDirectory($user->username);
}
$completeFileName = $user->username.'/'.$title.time();
Storage::put($completeFileName, file_get_contents($file), 'public');
$this->url = File::baseUrl().$completeFileName;
$this->title = $title;
$this->user_id = $user->id;
$this->save();
return $this;
}
public static function baseUrl()
{
return 'https://'.env('DO_SPACES_BUCKET').'.nyc3.digitaloceanspaces.com/';
}
public static function directoryExists($directory)
{
$existingDirs = Storage::directories();
return in_array($directory, $existingDirs);
}
添加异常的堆栈跟踪:
(1/1) FatalThrowableError
Class 'SimpleXMLElement' not found
in PayloadParserTrait.php (line 39)
at RestXmlParser->parseXml(object(Stream))
in RestXmlParser.php (line 33)
at RestXmlParser->payload(object(Response), object(StructureShape), array())
in AbstractRestParser.php (line 62)
at AbstractRestParser->__invoke(object(Command), object(Response))
in RetryableMalformedResponseParser.php (line 37)
at RetryableMalformedResponseParser->__invoke(object(Command), object(Response))
in AmbiguousSuccessParser.php (line 58)
at AmbiguousSuccessParser->__invoke(object(Command), object(Response))
in GetBucketLocationParser.php (line 30)
at GetBucketLocationParser->__invoke(object(Command), object(Response))
in WrappedHttpHandler.php (line 126)
at WrappedHttpHandler->parseResponse(object(Command), object(Request), object(Response), array())
in WrappedHttpHandler.php (line 93)
at WrappedHttpHandler->Aws\{closure}(object(Response))
in Promise.php (line 203)
【问题讨论】:
-
检查命名空间,您可能需要使用
\SimpleXMLElement调用 -
它在 AWS 库中的某个地方...在我的代码中没有。
-
这可能会有所帮助。 stackoverflow.com/a/35834836/3305978
-
我在我的问题中附加了相同的链接。正如我在扩展列表中显示的那样,xml 和 simplexml 已经存在,但是当我运行 extensions_loaded('php-xml') 时,它返回 false。 php7.0-xml或者simplexml需要单独安装吗?