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 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
  • ¥15 dy网页ck不扫码解决方法
  • ¥15 如何能达到用ping0.cc检测成这样?如图
  • ¥15 关于#DMA固件#的问题,请各位专家解答!
  • ¥15 matlab生成的x1图不趋于稳定,之后的图像是稳定的水平线
  • ¥15 请问华为OD岗位的内部职业发展通道都有哪些,以及各个级别晋升的要求
  • ¥20 微信小程序 canvas 问题
  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照