正如这个问题的标题中简要描述的那样,我希望将直接从控制器生成的XML文件直接保存在Cloudinary中,而不是将其保存在本地(在公共文件夹中).

在设置代码时(因为我使用的是saveXML()方法),我必须首先在本地保存它,这样当它保存在Cloudinary上时,它会采用通过saveXML方法保存的文件的名称,然后将其保存在Cloudinary上.

因此,我希望将文件直接保存到Cloudinary,而不是保存在公用文件夹中.

能做到这一点吗?

这是我的代码(控制器):

 public function fatturaxml($id)
    {      

        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><mydoc></mydoc>');

        $xml->addAttribute('version', '1.0');
        $xml->addChild('datetime', date('Y-m-d H:i:s'));

        $person = $xml->addChild('person');
        $person->addChild('firstname', 'Mkenny');
        $person->addChild('secondname', 'Mary');
        $person->addChild('telephone', '000000000');
        $person->addChild('email', 'marymkenny@yahoo.com');

        $xml->saveXML('myxml.xml');

        $response = Response::make($xml->asXML(), 200);
        $response->header('Cache-Control', 'public');
        $response->header('Content-Description', 'File Transfer');
        $response->header('Content-Disposition', 'attachment; filename=test.xml');
        $response->header('Content-Transfer-Encoding', 'binary');
        $response->header('Content-Type', 'text/xml');

        cloudinary()->uploadFile('myxml.xml', ['folder' => 'FolderTest',])->getSecurePath();
    }

我也试着写

cloudinary()->uploadFile($xml, ['folder' => 'FolderTest',])->getSecurePath();

但我得到以下错误: Missing required parameter - file

推荐答案

a quick search reveals this in the documentation: Parameter: File
Type: String
Description part 2:
the actual data (byte array buffer). For example, in some SDKs, this could be an IO input stream of the data (e.g., File.open(file, "rb")).

这应该意味着你可以做cloudinary()->uploadFile($xml, ['folder' => 'FolderTest',])->getSecurePath();个这样的事情

编辑

读取应该返回XML内容的asXML()方法的SimpleXMLElement docs.

如果未指定文件名,则此函数在成功时返回字符串,在错误时返回FALSE.

我会试着把它重写成cloudinary()->uploadFile($xml->asXML(), ['folder' => 'FolderTest',])->getSecurePath();

因为这是一个字符串,它应该可以工作(我还没有try 过这个)

Php相关问答推荐

过滤WooCommerce管理员订单列表(+HPOS)中包含其作者产品的订单

显示WooCommerce当前产品类别或标签的短代码

PHP中冒号的奇怪用例

EBay Inventory API createOrReplaceInventoryItem出错

针对给定产品类别的WooCommerce计数审核

fpm-php + nginx + POST数据

如何在自定义邮箱内容中获取WooCommerce订单项目的详细信息?

向元素添加类时添加循环错误

在 PHP 8.2 中使用 PHP Spreadsheet 和 CodeIgniter 3 导出 Excel 时出错

如何在WooCommerce管理产品列表中显示运输类别列

在这个 Laravel 应用中,如何仅显示已批准的 comments 回复?

Laravel使用另一张表进行关联查询

自定义主键值未正确显示

如何使用 WhatsApp Cloud API 向 WhatsApp 发送消息,而无需在发送消息之前注册收件人号码?

在 PHP 中验证签名

PDO 和 SQL 查询结果中日期格式不同的原因可能是什么?

NetBeans 不显示中文内容

如何为多个表的id列设置不同的值

使用 --exclude-dir 选项从 PHP 执行 grep 时出现问题

将参数传递给 laravel 9 工厂