0

所以我正在尝试在我的 Google Cloud App Engine 中使用 PHP 编写一个 PPT 文件。

写入文件的最终代码是

$xmlWriter = IOFactory::createWriter($phpPresentation, "PowerPoint2007");
$xmlWriter->save("php://output");

它在我的本地主机中工作,但是当我将它部署到谷歌云时,它ERR_INVALID_RESPONSE在谷歌浏览器和File Not Foundmozilla firefox 中出现错误。

当我访问日志时,它说

PHP Fatal error:  Uncaught exception 'Exception' with message 'Could not close zip file vfs://root/temp/.//phppttmp569a45e921e8a8.63056743.' in /base/data/home/apps/s~frrolefrontend/mediascout:ms-080.390023055217794078/mediascout/ppt_export/src/PhpPresentation/Writer/PowerPoint2007.php:320
Stack trace:
#0 /base/data/home/apps/s~frrolefrontend/mediascout:ms-080.390023055217794078/mediascout/ppt_export/samples/Sample_Header.php(72): PhpOffice\PhpPresentation\Writer\PowerPoint2007->save('php://output')
#1 /base/data/home/apps/s~frrolefrontend/mediascout:ms-080.390023055217794078/mediascout/ppt_export/samples/scout_temp.php(381): write(Object(PhpOffice\PhpPresentation\PhpPresentation), 'scout_temp', Array)
#2 {main}
  thrown in /base/data/home/apps/s~frrolefrontend/mediascout:ms-080.390023055217794078/mediascout/ppt_export/src/PhpPresentation/Writer/PowerPoint2007.php on line 320

在做了一些研究后,我发现这Uncaught exception 'Exception' with message 'Could not close zip file是因为目录不可写。

您能告诉我如何在 App Engine 中创建可写目录吗?

4

1 回答 1

1

你不能。Appengine 应用程序没有文件系统的写入权限。来自文档:

沙箱隔离您的应用程序以提高可靠性、可扩展性和安全性。出于这个原因,App Engine 上没有少量的 PHP 函数,如果使用不正确,其他函数会引发异常。例如,应用程序无法将数据写入本地文件系统。相反,应用程序可以使用 Google 提供的可扩展服务来存储和处理数据并通过 Internet 进行通信。

(来自https://cloud.google.com/appengine/features/

您必须使用 Google Cloud Storage 存储桶来写入文件:

<?php
file_put_contents('gs://my_bucket/hello.txt', 'Hello');

有一些例子https://cloud.google.com/appengine/docs/php/googlestorage/

于 2016-01-16T14:14:00.807 回答