the below script, when I reference the URL, if I shorten it in any way, it fails to locate the files, however when left full-length, it outputs the full server url to the link and the href – is there a correct way to change the included directory to prevent this?
<?php
function getFiles($dir)
{
$arr=scandir($dir);
$res=array();
foreach ($arr as $item)
{
if ($item=='..' || $item=='.'){continue;}
$path=$dir.'/'.$item;
if (is_dir($path))
{
$res=array_merge($res,getFiles($path));
}
else
{
$res[$path]=filemtime($path);
}
}
return $res;
}
$files=getFiles('/var/www/vhosts/mysite.com/httpdocs/Manuals/');
arsort($files);
$files=array_slice(array_keys($files),0,11);
foreach ($files as $file)
{
echo '<a href="'.$file.'">'.$file.'</a><br />';
}
?>
Reference those files as relative to the script’s
__FILE__and usedirname(...)to get the full, actual path. Then you can output the relative URLs in the html: