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.

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大