PDF='MAIN' { ATTRIBUTES='*' { PLATFORM='php.txt'; REPTYPE='1'; ATTACHED='0'; PROJECT='36'; OBJECTNAME='directory.php'; LIBLOBJ='*FILES'; TITLE='Directory Listing'; WEBPATH='http://esdi.excelsystems.com/wsexmpphp/'; TARGETPATH='/www/zendcore/htdocs/examples/'; FTPSITE='examples'; SET='149'; VERSION='4.00'; CRTBNUM='Revision 1702'; CRTTEMPLT='C:\\Program Files\\ESDI\\WebSmart\\Temp\\PHP-A Simple Page.tpl'; SAVBNUM='Revision 1811'; LASTLOC='1'; VHTML='N'; LASTSAVE='12/13/2007 10:23:52'; OBJLIBRARY='WEBTEST'; SOURCELIBR='WEBTEST'; SOURCEFILE='QRPGLESRC'; } FTPREFINFO='*' { URL='192.168.0.100'; INITIALDIR='/www/zendcore/htdocs/examples/'; FTPPORT='21'; PASSIVEMODE='1'; WEBPATH='http://esdi.excelsystems.com/webtest/'; } PANELS='*' { PANEL='MainSeg' { DESC='Main Segment'; DETAILS=' Directory Listing

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
'; } PANEL='listing' { DESC='listing segment'; DETAILS=' '; } PANEL='footer' { DESC='footer segment'; DETAILS='
SeqFile Name(Click on the file name to view or download)
  1. Start with a \'A Simple Page PHP\' from one of the PHP template families.


  2. Create two new segments, listing and footer.
    (You can create new segment by choosing Attributes and then Segments from the menu)


  3. 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>
                          

  4. Create a global variable: $filenum near the top of your PHP source code:

        global $filenum;
        				
  5. 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>
        				   
  6. 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



  7. 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\');
    }
                          


  8. Compile and run your program

Program Definition:   directory.phw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } } PREVIEWS='*' { DEFAULT='MainSeg'; PREVIEW='MainSeg' { SEG='MainSeg'; } } ACTIONS=' // Program Name: directory.php // Program Title: Directory Listing // Created by: SPOT // Template family: Idaho // Template name: Simple Page // Purpose: // Program Modifications: require(\'/esdi/websmart/v6.6/include/xl_functions001.php\'); global $wsnum, $filenum; // This code is for the Rate this page section if (isset($_REQUEST[\'wsnum\'])) { $wsnum = $_REQUEST[\'wsnum\']; } // Check the cookie if(isset($_COOKIE[\'wsnumbc\'])) { $wsnum = $_COOKIE[\'wsnumbc\']; } else { setcookie(\'wsnumbc\', $wsnum); } // Retrieve the task (default to "default") if ($pf_task == \'default\') generic(); function generic() { wrtseg(\'MainSeg\'); if ($handle = opendir(\'/esdi/websmart/wsdemo/musicstore\')) //put here your own folder e.g. opendir(\'c:\\\\temp\') { $filenum = 1; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if($filenum % 2 == 0) { $rowcol = "#C3C3C3"; } else { $rowcol = "#ffffff"; } echo "$filenum$file"; $filenum = $filenum + 1; } } wrtseg(\'listing\'); } wrtseg(\'footer\'); } '; }