Reputation: 13
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
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
Reputation: 579
Try this function for get fullpath of file,
<?php
echo realpath("your file name");
?>
Upvotes: 0