I have a webapp which reads and interprets .rptdesign files. All .rptdesgn files are located in a maindirectory within the webapp (./report/)
For instance:
report/
file1.rptdesign
file2.rptdesign
subdirectory1/
file3.rptdesign
file4.rptdesign
...
The link to access file3.rptdesign looks like this: server1.com/webapp/frameset?__report=report/subdirectory/file3.rptdesign
I want to have list of all and only .rptdesign files. When I click one the link needs to be build with the directory and the filename. I have something like this which works, if I put all .rptdesign files in a one level directory without any subdirecotries:
<%@ page language="java" import="java.io.*" pageEncoding="UTF-8"%>
<html>
<head>
<meta content="text/html; charset=UTF-8" />
<title>Web course code example</title>
</head>
<body>
<ul style="font-size:16px;">
<%
String path = application.getRealPath("report");
out.println("<p>Reports</p><br/>");
File f = new File(path);
File[] files = f.listFiles();
if(files.length == 0){
out.println("<p>Nothing</p><br/>");
return;
}
for(int i=0; i<files.length; i++){
if (files[i].isFile()){
String fname = files[i].getName();
int last_index = fname.lastIndexOf(".");
if(last_index == -1){
continue;
}
String suffix = fname.substring(last_index);
if(suffix.equals(".rptdesign")){
out.print("<li>");
out.print("<a href='./frameset?__report=report/" + fname + "'>");
out.println(fname);
out.print("</a>");
out.print("</li>");
}
}
}
%>
</ul>
</body>
</html>
But I want to have something like this: Listing all the folders subfolders and files in a directory using php
<html>
<body>
<?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('Main Dir');
?>
</body>
</html>
The problem is that in this mentioned php code I am little bit lost, how I can add the href part and how I can only filter all the .rptdesign files like I did in my jsp with the suffix if. At the end I want to see the list like this in the browser and be able to click the correct builded links to the .rptdesign files:
file1.rptdesign
file2.rptdesign
subdirectory1/
file3.rptdesign
file4.rptdesign