GAE:file_get_contents()和静态文件 [英] GAE: file_get_contents() and static files

查看:82
本文介绍了GAE:file_get_contents()和静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解析文件并提取所需的位,而不是在各个位置更新相同的变量.我要寻找的是我的service-worker.js文件中的缓存名称.在本地进行开发时,我可以轻松地在目录结构中检索js文件.

Instead of updating the same variable in various locations I parse files and extract the bits I need. One bit I am looking for is the cache name in my service-worker.js file. When I'm developing locally, I can easily retrieve the js file in the directory structure.

将我的应用程序部署到GAE时,需要将服务工作者JS文件声明为静态,因此GAE会将其存储在某个地方.

When I deploy my app to GAE, the service worker JS file needs to be declared static and so GAE stashes it away somewhere.

有没有一种方法可以在不进行URL调用的情况下访问此文件?

Is there a way to get to this file without making a URL call?

这是我目前使用的,并且在DEV中一切正常:

This is what I currently use and it's all working fine in DEV:

<?php
function getCacheId() {
    $cache_id = "";
    $c = file_get_contents ( dirname ( __FILE__ ) . "/service-worker.js" );
    if (preg_match ( "/CACHE_NAME = '(.*)'/", $c, $matches ) !== false) {
        if (count ( $matches )) {
            $cache_id = trim ( $matches[1] );
        }
    }
    return $cache_id;
}
?>
<script>
    const CACHEID = "<?php echo getCacheId() ?>";
</script>

推荐答案

除了app.yaml文件中的静态文件声明之外,您还需要配置application_readable: true.

You need to also configure application_readable: true in addition to the static file declaration in your app.yaml file.

来自处理程序元素:

应用可读

可选.布尔值.默认情况下,在静态文件处理程序中声明的文件 作为静态数据上传,并且仅提供给最终用户.他们 应用程序无法读取.如果此字段设置为true,则 文件也作为代码数据上传,因此您的应用程序可以读取 他们.两次上传均会根据您的代码和静态数据收费 存储资源配额.

Optional. Boolean. 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.

这篇关于GAE:file_get_contents()和静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆