无法使用 PHP 写入 Google App Engine 开发服务器上的文件?

Cannot write to file on Google App Engine Dev server with PHP?

我几个小时前才真正开始工作。不知道我做了什么把它搞砸了,如果有的话。我正在尝试对临时目录中的 test.txt 文件使用 file_put_contents() 来测试一些东西。我不能使用 print_r() 或 echo,因为有时它是我正在测试的 ajax 调用。我不断收到的错误是:

Warning: file_put_contents(temp/test.txt): The local filesystem is readonly, open failed in sub-dirs.../request.php on line 62

Warning: file_put_contents(temp/test.txt): failed to open stream: No such file or directory in sub-dirs.../request.php on line 62

我不在制作中。这是本地的,根据文档,这应该有效:

Storing data in the development web server

Google App Engine for PHP supports reading and writing to Google Cloud Storage via PHP's streams API. A developer can read to and write from an object in Google cloud storage by specifying it as a URI to any PHP function that supports PHPs Streams implementation such as fopen(), fwrite() or get_file_contents().

In the Development Server, when a Google Cloud Storage URI is specified we emulate this functionality by reading and writing to temporary files on the user's local filesystem. These files are preserved between requests, allowing you to test the functionality on your local development environment before deploying your code to App Engine.

In the PHP development server streaming calls like fopen(), file_get_contents() on 'gs://' urls are mocked by reading and writing to the local filesystem.

我很沮丧,所以非常感谢任何帮助。会投票的。

虽然你是对的,但开发服务器应该能够模拟 Google 云存储,目前有一个问题(已报告 here,请随时加注星标)。

如果您使用的是 SDK 版本 1.9.18,只需恢复到 1.9.17,它应该可以工作(至少对我有用)

从SDK 1.9.18开始,dev_appserver默认关闭本地文件写入,更好的模拟生产环境。您可以通过将 "google_app_engine.disable_readonly_filesystem=1" 添加到 php.ini 文件来启用文件写入。