php how to go one level up on dirname(__FILE__)

后端 未结 9 2051
暗喜
暗喜 2020-11-30 21:52

I have a folder structure as follows:

mydomain.com
  ->Folder-A
  ->Folder-B

I have a string from Database that is \'../Folder-B/imag

9条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 22:29

    For PHP < 5.3 use:

    $upOne = realpath(dirname(__FILE__) . '/..');
    

    In PHP 5.3 to 5.6 use:

    $upOne = realpath(__DIR__ . '/..');
    

    In PHP >= 7.0 use:

    $upOne = dirname(__DIR__, 1);
    

提交回复
热议问题