PHP file_exists 函数在 Google App Engine 中是否有效?

Does the PHP file_exists function work in Google App Engine?

当我将php 文件部署到GAE 时,file_exists 功能不起作用。如果我使用 Google App Engine Launcher 从我的计算机本地测试完全相同的代码,它就可以工作。这是 PHP 和 app.yaml 文件

indexTest.php

<?php
DEFINE("TESTFILE", 'testfile.txt');
echo TESTFILE.'<br>';

$doesTheFileExist = file_exists(TESTFILE);
echo '$doesTheFileExist: ' . $doesTheFileExist. '<br>';

if (!file_exists(TESTFILE)) {
  echo 'I guess it doesnt exist';
}

RETURN;

app.yaml

application: application-name
version: 1
runtime: php55
api_version: 1
threadsafe: true

handlers:

- url: /favicon.ico
  static_files: favicon.ico
  upload: favicon.ico

- url: /google-api-php-client
  script: google-api-php-client

- url: /testfile.txt
  static_files: testfile.txt
  upload: testfile.txt

- url: /
  script: indexTest.php

本地输出

GAE 上的输出

为什么本地测试可以,部署后就不行了?

我尝试更改文件的位置并更改 app.yaml 文件,并添加如下内容:

- url: /templates
  static_dir: templates

并将文件放在 templates 目录中。但同样,它在本地主机上工作,但没有部署到 App Engine。

如果您希望能够从应用中读取静态资源,则需要在处理程序上设置 application_readable 标志。

当然,如果您实际上并不希望能够将文件作为静态资源提供,而只是希望能够读取它,那么甚至不要将它包含在您的 app.yaml 文件中它将被上传并从您的应用程序访问。

查看文档 here