PHP常用文件路径操作方法。
<?php //——FILE__返回文件完整路径 $dir = dirname(__FILE__); echo $dir; ?> <?php $path = "/usr/www/html/index.php"; echo basename($path)."<br>"; //如果选择suffix则忽略扩展名 echo basename($path,".php"); ?> <?php $path = "/usr/www/html/index.php"; $pathinfo = pathinfo($path); echo "目录名称:$pathinfo[dirname]<br>"; echo "文件名称:$pathinfo[basename]<br>"; echo "扩展名:$pathinfo[extension]"; ?> <?php $path = "./exercise/php.txt"; $realpath = realpath($path); echo $realpath; ?>