Home >Backend Development >PHP Tutorial >PHP获取当前文件路径,下层目录路径

PHP获取当前文件路径,下层目录路径

ringa_lee
ringa_leeOriginal
2018-05-14 16:56:034368browse

  PHP获取当前文件路径,上层目录路径
   例如:/var/www/project/test.php
获取路径加文件名

echo __FILE__;//输出/var/www/project/test.php

只获取文件名

echo basename(__FILE__);//输出test.php

获取文件名,但不含文件的扩展名

echo basename(__FILE__,'.php');//此处文件扩展名可替换成其他类型

获取当前路径,但不含文件名

echo dirname(__FILE__); //输出/var/www/project//或者echo getcwd(); //输出/var/www/project

获取上层目录的路径

echo dirname(dirname(__FILE__)); //输出/var/www
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP面试有关问题考卷02Next article:关于php vps 治理