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

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

WBOY
Release: 2016-06-13 13:04:18
Original
856 people have browsed it

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

获取路径加文件名

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


只获取文件名
echo basename(__FILE__);//输出test.php
Copy after login


获取文件名,但不含文件的扩展名
echo basename(__FILE__,'.php');//此处文件扩展名可替换成其他类型
Copy after login


获取当前路径,但不含文件名
echo dirname(__FILE__); //输出/var/www/project
//或者
echo getcwd(); //输出/var/www/project
Copy after login


获取上层目录的路径
echo dirname(dirname(__FILE__)); //输出/var/www
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template