doujiao3072 2015-10-26 21:41
浏览 46
已采纳

在GAE上使用PHP读取目录

I'm trying to read a directory with php's scandir on Google App Engine. The files within the folder 'img' are definitely reachable, but I am trying to get a list of all files in the folder. What's wrong?

All files are apparently uploaded correctly, so app.yaml should be fine. Is it a PHP error or a GAE restriction?

This is my main php-script, run when accessing my site's /:

   <?php

    $dir = 'img';
    if (is_dir($dir)) {
        //this code is never reached:
        echo "directory exists :-)";
        $filenames = scandir($dir, 0);
        print_r($filesnames);
    } else {
        echo "No such directory";
    }

    // this works:
    echo "<div>
        <img src=\"/img/example.png\">
    </div>";

    // this works:
    $files1 = scandir(getcwd());
    print_r($files1);

    ?>

opendir($dir) doesnt help either.

Here's my app.yaml:

application: mypage
version: 1
runtime: php55
api_version: 1

handlers:

# image files
- url: /img/(.*\.(bmp|gif|ico|jpeg|jpg|png))
  static_files: img/\1
  upload: img/(.*\.(bmp|gif|ico|jpeg|jpg|png))

- url: /.*
  script: helloworld.php

# this is probably redundant:
- url: /img
  static_dir: img

EDIT: Adding this line to the image files section (not necessarily the img folder) solved the problem: application_readable: true

  • 写回答

1条回答 默认 最新

  • doumeng3345 2015-10-26 22:25
    关注

    From the documentation:

    application_readable

    Optional. By default, files declared in static file handlers are uploaded as static data and are only served to end users, they cannot be read by an application. If this field is set to true, the files are also uploaded as code data so your application can read them. Both uploads are charged against your code and static data storage resource quotas.

    Try adding the application_readable flag to the img handler. I'm not 100% sure if the flag will also cover the img dir itself in addition to its content. It's worth a try.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?