【发布时间】:2023-04-10 15:41:01
【问题描述】:
就在几个小时前,我才真正开始了这项工作。不知道我做了什么把它搞砸了,如果有的话。我正在尝试使用 file_put_contents() 到我的临时目录中的 test.txt 文件来测试一些东西。我不能使用 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
我不在生产中。这是本地的,根据文档,这应该可以工作:
在开发网络服务器中存储数据
Google App Engine for PHP 支持通过 PHP 的流 API 读取和写入 Google Cloud Storage。开发人员可以通过将对象指定为支持 PHP 流实现的任何 PHP 函数(例如 fopen()、fwrite() 或 get_file_contents() 的 URI)来读取和写入 Google 云存储中的对象。
在开发服务器中,当指定 Google Cloud Storage URI 时,我们通过读取和写入用户本地文件系统上的临时文件来模拟此功能。这些文件在请求之间保留,允许您在将代码部署到 App Engine 之前在本地开发环境中测试功能。
在像 fopen() 这样的 PHP 开发服务器流式调用中,'gs://' url 上的 file_get_contents() 通过读取和写入本地文件系统来模拟。
我很沮丧,所以非常感谢任何帮助。会投票。
【问题讨论】:
-
FWIW "temp/test.txt" 不是云存储路径。在 1.9.18 中,我们添加了对内存临时文件系统的支持,因此您可以执行类似 file_put_contents(sys_get_temp_dir() . '/test.txt', 'blah') 之类的操作
标签: php google-app-engine development-environment file-writing