Example 141: List the Files in an IFS Directory (PHP)
| Description: |
This Example will demonstrate how to display and access the contents of a folder on the IFS. |
|
This example uses the opendir() and the readdir() PHP functions |
| Seq | File Name(Click on the file name to view or download) | ';
}
PANEL='listing'
{
DESC='listing segment';
DETAILS='
';
}
PANEL='footer'
{
DESC='footer segment';
DETAILS='
-
Start with a \'A Simple Page PHP\' from one of the PHP template families.
-
Create two new segments, listing and footer.
(You can create new segment by choosing Attributes
and then Segments from the menu)
-
Add this in between the <head> and </head> tags in the Main segment:
<style type="text/css">
#row a:link {color:#000000;}
#row a:hover {color:#fffff;}
#row a:visited {color:#FF0000;}
</style>
-
Create a global variable: $filenum near the top of your PHP source code:
global $filenum;
-
Add the following code in the Main segment after the <div id="contents">
<table>
<tr><td>Seq</td><td><Strong>File Contents</strong></td></tr>
</table>
-
In the Main segment, cut everything after:
<tr><td>Seq</td><td><Strong>File Contents</strong></td></tr>
and paste it into the footer segment
-
In the PHP source code replace the generic() function with this code:
function generic()
{
wrtseg(\'MainSeg\');
//put here your own folder e.g. opendir(\'c:\\\\temp\')
if ($handle = opendir(\'/esdi/websmart/wsdemo/musicstore\'))
{
$filenum = 1;
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if($filenum % 2 == 0)
{
$rowcol = "#C3C3C3";
}
else
{
$rowcol = "#ffffff";
}
echo "<tr id=\\"row\\" bgcolor=\\"$rowcol\\"><td>$filenum</td>
<td>
<Strong><a href=\\"/wsdemo/musicstore/$file\\">$file</a></Strong>
</td>
</tr>";
$filenum = $filenum + 1;
}
}
wrtseg(\'listing\');
}
wrtseg(\'footer\');
}
-
Compile and run your program
|