PHP:在谷歌云存储中保存“动态文本或pdf内容”?

2024-01-12

运行时:php

GCS文件上传流程:

$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($file, [
  'name' => $objectName
]);

现在我想用动态文本/pdf 创建对象而不是使用$source路径文件。

例如:

$storage = new StorageClient();
$objectName = "newfile.txt";
$content = "This is the dynamic content";
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($content, [
    'name' => 'textDocs/'.$objectName
]);

因此它将创建新对象“newfile.txt”,内容为“这是动态内容”。

有没有任何云库或函数来处理这个?
提前致谢


对于在 Google 云存储中动态创建文本文档(带有动态内容),下面的代码将完美工作。

$storage = new StorageClient();
$objectName = "newfile.txt";                  // name of object/text-file
$content = "This is the dynamic content";     // assign static/dynamic data to $content variable
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($content, [
    'name' => 'textDocs/'.$objectName
]);

用于在 Google 云存储中动态创建 pdf 文档(带有动态内容)。

$name = "samplePDF.pdf";
$p = new PDFTable("L");
$p->AddPage();
$p->setfont('helvetica','',12);
$p->htmltable($html);
$pdfData = $p->output("",'S'); // returns pdf as string
$filename = "pdfDocs/".$name;
/** 
 * file uploading into google cloud storage : start
 */
$storage->bucket($bucketName, true)->upload(
    $pdfData,
    [
    'name' => $filename,
    'predefinedAcl' => 'publicRead'
    ]
);
/** 
 * file uploading into google cloud storage : end
 */
$p->output($name,"D"); // D->downloads file in our system.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PHP:在谷歌云存储中保存“动态文本或pdf内容”? 的相关文章

随机推荐