开发者

PHP: let a file return its own directory

开发者 https://www.devze.com 2023-02-28 16:45 出处:网络
I am having trouble finding the rigth director开发者_运维知识库y on my online server. is there a function that returns the folder the file is stored in?In PHP>=5.3 use __DIR__ and before use dirname(_

I am having trouble finding the rigth director开发者_运维知识库y on my online server. is there a function that returns the folder the file is stored in?


In PHP>=5.3 use __DIR__ and before use dirname(__FILE__)

http://php.net/constants.predefined

http://php.net/dirname


Use the magic constant __DIR__

You can read more about the magic constants here: http://php.net/manual/en/language.constants.predefined.php


http://php.net/manual/en/function.getcwd.php

Returns the current working directory on success, or FALSE on failure.


The dirname() function will return the directory portion of a path. For example, dirname('foo/bar/baz.php') will return foo/bar.

This is often used in conjunction with the __FILE__ magic constant for versions of PHP that do not support the __DIR__ magic constant (versions 5.2.x and below):

require_once dirname(__FILE__) . '/../classes/Class.php';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号