Ethan E10
Ethan E10

Reputation: 13

how to get full directory path of a file or folder using php

I use this code to list the folders and files I have inside of a certain directory, but I need the full path of each one of them. eg. C:\Users\houdi\Desktop\03012018134338-0001.pdf

 <?php
 function listFolderFiles($dir){
 $ffs = scandir($dir);

 unset($ffs[array_search('.', $ffs, true)]);
 unset($ffs[array_search('..', $ffs, true)]);

 // prevent empty ordered elements
 if (count($ffs) < 1)
    return;

 echo '<ol>';
 foreach($ffs as $ff){
     echo '<li>'.$ff;
     if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
     echo '</li>';
 }
 echo '</ol>';
 }

 listFolderFiles('C:\Users\hsaoudi\Desktop\Haithem');

?>

Upvotes: 1

Views: 377

Answers (2)

Ravi Shrimali
Ravi Shrimali

Reputation: 131

Try the below code to get the full path I hope it work for you..

<?php
      $FullPath = realpath($_SERVER["DOCUMENT_ROOT"]);
      //include_once "$FullPath/stack/db.php";
      echo "$FullPath/stack/db.php";
?>

If above not working then try:

<?php
      $dir = dirname(__FILE__);
      echo $dir;
?>

Upvotes: 1

Dhaval Naphade
Dhaval Naphade

Reputation: 579

Try this function for get fullpath of file,

<?php
echo realpath("your file name");
?>

Upvotes: 0

Related Questions