file_get_contents with relative path

前端 未结 4 668
孤独总比滥情好
孤独总比滥情好 2020-12-08 19:29

I have the following directory structure.

/var/www/base/controller/detail.php
/var/www/base/validate/edit.json
/var/www/html

Within /

4条回答
  •  一向
    一向 (楼主)
    2020-12-08 19:35

    You can always try to do the opposite first to find out:

    file_put_contents('FINDME', 'smth');
    exit();
    $json=file_get_contents('detail.php');
    ...
    

    Then run something like this from your terminal on *nix system (or search for a file named FINDME using GUI on Windows)

    find  -name 'FINDME'
    

    The command will output something like this:

    //FINDME
    

    Now you know the root dir (from which the relative path is being taken) for the file where you are attempting to read the other files and you can construct the relative path easily

提交回复
热议问题