0

So I am trying to write a PPT file using PHP in my Google Cloud App Engine.

The final code to write the file is

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

It is workng in my Localhost but when I deploy it to google cloud it gives the error ERR_INVALID_RESPONSE in google chrome and File Not Found in mozilla firefox.

When i accessed the logs it says

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

After doing some research i found that Uncaught exception 'Exception' with message 'Could not close zip file is because the directory is not writable.

Can you tell me how can i make a directory in App Engine Writable?

void
  • 36,090
  • 8
  • 62
  • 107

1 Answers1

1

You cannot. Appengine Apps doesn't have write access to filesystem. From docs:

The sandbox isolates your application for reliability, scalability and security. For this reason, a small number of PHP functions are not available on App Engine, and others will raise an exception if used incorrectly. For instance, an app cannot write data to the local file system. Instead, apps can use scalable services provided by Google to store and process data and communicate over the Internet.

(from https://cloud.google.com/appengine/features/)

You have to use Google Cloud Storage bucket to write files:

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

There're some examples https://cloud.google.com/appengine/docs/php/googlestorage/

Igor Artamonov
  • 35,450
  • 10
  • 82
  • 113