php - 找不到类 'SimpleXMLElement'

标签 php laravel amazon-s3

我正在尝试在我的 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/

相关文章:

php - 输入在 Laravel 中不起作用时重定向回来

php - 使用查询范围但具有不同的查询模型 - Laravel

apache-spark - Spark 避免在 S3 中创建 _temporary 目录

php - 什么在 SilverStripe 表单中生成 .holder-required 类

类似于 Wordpress 的 PHP 短 URL

php - 多维数组,找到所选值的键

mysql - 从数据库中搜索包含某些字符的字符串 laravel 5

php - php中如何获取字符串的宽度?

amazon-s3 - 为什么 boto 可能会被拒绝使用正确的 IAM key 访问 S3?

amazon-s3 - Amazon S3 错误 - 当前正在针对此资源执行冲突的条件操作。