I am using the below code to read files I have saved on my server in folders.
<?php
if ($handle1 = opendir('../files/policies/fire')) {
while (false !== ($file1 = readdir($handle1))) {
if ($file1 != "." && $file1 != "..") {
$thelist1 .= '<li><a href="'.$file1.'" target="_blank">'.$file1.'</a></li>';
}
}
closedir($handle1);
}
?>
<h3>Fire Fighting Files:</h3>
<ul><?php echo $thelist1; ?></ul></h6>
The code reads the files in the directory as it should. The issue I am having is once I click the link it searches or attempts to open the file in the root directory
It does not use the sub-dir to open the file but the root dir. The structure is as follow
/File
/policies
/FA
When I click the link it tries finding the file as below
/files/OHS_EHSR-020%20Employee%20Health%20and%20Safety%20Rules.pdf
and the file is saved as
/files/policies/FA/OHS_EHSR-020%20Employee%20Health%20and%20Safety%20Rules.pdf
Any suggestions would help. Please note my code I am using I took from this site as well
ADDING Full Code of two blocks this is why I cannot fix the directories to static in my code:
<div class="col-xl-5 col-md-5 col-12">
<div class="box box-body">
<h6 class="text-uppercase">
<?php
if ($handle = opendir('../files/policies/FA')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$thelist .= '<li><a href="'.$file.'" target="_blank">'.$file.'</a></li>';
}
}
closedir($handle);
}
?>
<h3>First Aid Files:</h3>
<ul><?php echo $thelist; ?></ul></h6>
</div>
</div>
<!-- /.col -->
<div class="col-xl-5 col-md-5 col-12">
<div class="box box-body">
<h6 class="text-uppercase">
<?php
if ($handle1 = opendir('../files/policies/fire')) {
while (false !== ($file1 = readdir($handle1))) {
if ($file1 != "." && $file1 != "..") {
$thelist1 .= '<li><a href="'.$file1.'" target="_blank">'.$file1.'</a></li>';
}
}
closedir($handle1);
}
?>
<h3>Fire Fighting Files:</h3>
<ul><?php echo $thelist1; ?></ul></h6>
</div>
</div>
'<li><a href="/files/policies/FA/'.$file1.'" target="_blank">'.$file1.'</a></li>';? Also, are you sure you would want to show actual file path of the server?