我正在尝试在我的php7 laravel项目中使用数字海洋空间。代码非常简单,只需加载一个文件并将其复制到目录。一切工作在我的本地机器上,但失败在我的数字海洋服务器与此错误
未找到类'Uncategorized'
即使在数字海洋服务器上,如果我使用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)
9条答案
按热度按时间v2g6jxz61#
检查安装的php版本使用:-
如果是版本7,则安装php7.0-xml
如果是7.2.* 版,则在您机器上使用php7.2-xml包沿着php。
bbmckpt72#
只需安装php-xml包。作为参考,只需安装所有其他php库:
apt-get install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml
k10s72fa3#
最后,我只需要遵循我在问题中提到的相同的answer。安装php7.0-xml和simplexml必须安装和apache服务器重新启动,以使其工作。因此,即使加载的扩展显示已安装的xml和simplexml,您可能仍然需要安装php7.0-xml和simplexml。
n3h0vuf24#
你必须在SimpleXMLElement前面加上\ slash(在laravel中)来调用xml元素类
xmakbtuz5#
要解决这个问题,请安装最新版本的php-xml,运行以下命令:
别忘了重启Apache:
j2cgzkjk6#
我解决了运行这个命令
6tr1vspr7#
试试看
然后再打电话给班级。
3hvapo4f8#
我在一个Docker容器中遇到了这个问题,发现我实际上并没有像我想的那样安装和启用SimpleXML。
phpinfo()
提到了SimpleXML,但是,如果没有一个标题为“SimpleXML”的部分说:那么SimpleXML就不存在。即使添加并启用了
php-xml
,SimpleXML也不会。为了解决这个问题,我必须将
php-simplexml
(或者,在我的情况下,PHP 8.1的php81-simplexml
)添加到我的Dockerfile中,然后一切都开始工作。r9f1avp59#
安装后必须重新启动apache2
systemctl apache2 restart