PHP:在谷歌云存储中保存“动态文本或 pdf 内容"? [英] PHP: Save 'dynamic text or pdf content' in google cloud storage?
本文介绍了PHP:在谷歌云存储中保存“动态文本或 pdf 内容"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行时:php
GCS文件上传流程:
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($file, [
'name' => $objectName
]);
现在我想用动态文本/pdf 创建对象,而不是使用 $source
路径文件.
Now i want to create object with dynamic text/pdf instead of using $source
path file.
例如:
$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",内容为这是动态内容".
so it'll create new object as "newfile.txt" with content "This is the dynamic content".
是否有任何云库或函数来处理这个?
提前致谢
is there any cloud libraries or functions to process this?
thanks in advance
推荐答案
对于在 Google-cloud-storage 中动态创建文本文档(with-dynamic-content),下面的代码可以完美运行.
$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-cloud-storage 中动态创建 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.
这篇关于PHP:在谷歌云存储中保存“动态文本或 pdf 内容"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文