PHP/File Directory/File

Материал из Web эксперт
Перейти к: навигация, поиск

dirname: get the directory name for a file

<?php
   $path = "./test.txt";
   $dirname = dirname($path);
   
   echo $dirname;
?>



File base name

<?php
   $path = "./test.txt";
   $filename = basename($path); 
   $filename2 = basename($path, ".txt"); 
   
   echo $filename;
   
   echo "<BR>";
   
   echo $filename2;
?>



realpath: Returns canonicalized absolute pathname

<?php
   $imgPath = "./text.txt";
   $absolutePath = realpath($imgPath);
   echo $absolutePath;
?>