GCP PHP Flex环境,由于缺少权限,复制功能失败

时间:2017-06-23 21:37:06

标签: php google-app-engine permissions copy

这是我的代码,它在本地运行很好但是当我部署它时,我得到一个奇怪的错误。

$url_doc = $url;
    $temp_doc = __DIR__. '/../temp.doc';
    if (!copy($url_doc, $temp_doc)) {
      $content = "Couldn't copy the file....";
    }

这是错误。

2017-06-23 21:21:36 default[20170623t151218]  [23-Jun-2017 21:21:36] WARNING: [pool app] child 36 said into stderr: "NOTICE: PHP message: PHP Warning:  copy(/app/app/../temp.doc):

我该如何纠正?我在Google应用引擎上运行PHP flex环境。

感谢。

2 个答案:

答案 0 :(得分:0)

我的建议是为此使用云存储,所有实例都可以从中进行写入和读取,因此您的文件可以从所有实例访问。

写入和读取云存储很容易,

写入云端存储

$file = 'gs://<your-bucket>/hello.txt';
file_put_contents($file, 'hello world');

从云存储中读取

$contents = file_get_contents($file);
var_dump($contents); 

据我所知,您无法在Google App Engine上写入文件。 (我猜的原因是,当流量较小时,您的实例会关闭,并且您关闭的实例上的文件将会丢失。)

答案 1 :(得分:0)

在App Engine Flexible Environment上,您可以写入文件系统,但某些目录受到保护。

对于临时文件,请使用/tmp目录或sys_get_temp_dir,如下所示:

$temp_doc = tempnam(sys_get_temp_dir(), 'Doc');
if (!copy($url_doc, $temp_doc)) {
  $content = "Couldn't copy the file....";
}
相关问题