runtime: php
GCS file uploading process:
$storage = new StorageClient();
$file = fopen($source, \'r\');
$bucke
For Dynamic creation of text document (with-dynamic-content) in Google-cloud-storage, below code will be work perfectly.
$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
]);
For Dynamic creation of pdf document (with-dynamic-content) in Google-cloud-storage.
$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.