gpt4 book ai didi

php - 找不到类 'SimpleXMLElement'

转载 作者:可可西里 更新时间:2023-11-01 12:48:17 28 4
gpt4 key购买 nike

我正在尝试在我的 php7 laravel 项目中使用 digital ocean 空间。代码非常简单,只需加载一个文件并将其复制到目录即可。一切都在我的本地机器上工作,但在我的 digital ocean 服务器上失败并出现此错误

Class 'SimpleXMLElement' not found

即使在 digital ocean 服务器上,如果我使用 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-xmlphp-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)

最佳答案

检查安装的 php 版本:-

$ php -v

如果是版本7,则安装php7.0-xml

如果是 7.2.* 版本,则在您的机器上使用 php7.2-xml 包和 php。

关于php - 找不到类 'SimpleXMLElement',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46610501/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com