PHP/File Directory/File

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

dirname: get the directory name for a file

   <source lang="html4strict">

<?php

  $path = "./test.txt";
  $dirname = dirname($path);
  
  echo $dirname;

?>

      </source>
   
  


File base name

   <source lang="html4strict">

<?php

  $path = "./test.txt";
  $filename = basename($path); 
  $filename2 = basename($path, ".txt"); 
  
  echo $filename;
  
  echo "
"; echo $filename2;

?>


      </source>
   
  


realpath: Returns canonicalized absolute pathname

   <source lang="html4strict">

<?php

  $imgPath = "./text.txt";
  $absolutePath = realpath($imgPath);
  echo $absolutePath;

?>


      </source>