【问题标题】:Writing files in Google Cloud using PHP使用 PHP 在 Google Cloud 中编写文件
【发布时间】:2016-01-16 14:06:07
【问题描述】:

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

写入文件的最终代码是

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

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

当我访问它说的日志时

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 中创建可写目录吗?

【问题讨论】:

    标签: php google-app-engine phpexcel phppowerpoint


    【解决方案1】:

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

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

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

    你必须使用谷歌云存储桶来写文件:

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

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

    【讨论】:

    • 我试过这样做,但它也给了我同样的错误。
    • 你能告诉我我需要做什么配置才能让它工作吗?我创建了一个桶。使用了网址,但它不起作用。
    • 你拿到桶里的文件了吗?你能用简单的文件而不是PowerPoint文件来写吗?
    猜你喜欢
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 1970-01-01
    • 2020-07-21
    • 2014-10-13
    相关资源
    最近更新 更多