【问题标题】:How to access the file in another folder file_get_contents()如何访问另一个文件夹中的文件 file_get_contents()
【发布时间】:2018-12-28 08:57:47
【问题描述】:

此文件正在运行

my-site.com/includes/classes/build/cg.php

它会加载

my-site.com/data/data.json

具有这样的结构

$data = json_decode(file_get_contents("http://my-site.com/data/data.json"), true);

我想用相关路径加载它,怎么做?

【问题讨论】:

    标签: php json path file-get-contents


    【解决方案1】:

    在尝试了一些组合之后,意识到了这一点:

    $data = json_decode(file_get_contents(__DIR__ ."/../../../data/data.json"), true);
    

    或

    $data = json_decode(file_get_contents("././././data/data.json"), true);
    

    【讨论】:

      猜你喜欢
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      • 2021-08-24
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多