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
SeqFile Name(Click on the file name to view or download)
100015S.GIF
200016SGT.GIF
30001R.GIF
400028EC.GIF
500028H.GIF
6000C15E.GIF
70015.GIF
80016DBM.GIF
900C16.GIF
1000CMAE.GIF
110131000_th.jpe
120131002_th.jpe
130136100_th.jpe
140136208_th.jpe
150136600_th.jpe
160137002_th.jpe
17110156Med.jpe
18116128.jpe
19780.jpe
20ACOUSTIC.GIF
21AGH1.JPEG
22AGHCLIP.JPEG
23AGHCORD.JPEG
24AGS1.JPEG
25ARMRESTS_JOHN_PEARSE_REDUCED.GIF
26BB6.GIF
27BLACKBELT_DREADNOUGHT.GIF
28BREKKE_MANDO_BRIDGE.GIF
29CC01B.jpe
30CHS.JPEG
31CLEANINGCLOTHS.GIF
32CP500BK.JPEG
33CP500CR.JPEG
34CP500GD.JPEG
35D'ADDARIOPROARTE.GIF
36D-16GT.GIF
37D-18V.GIF
38D-18VS.GIF
39D-28.GIF
40D-35.GIF
41D1.GIF
42D121.GIF
43D15.GIF
44D18.GIF
45D42K.GIF
46D45V.GIF
47DADDARIOPROARTE.GIF
48DADDARIO_COMPOSITES.GIF
49DADDARIO_ELECBASS.JPEG
50DADDARIO_ELECGUIT.JPEG
51DADDARIO_J61.GIF
52DADDARIO_PB_ACOUSTIC_SMALL.GIF
53DADDARIO_ZYEX.GIF
54DAMPIT.GIF
55DAWG_PICK.GIF
56DC-16RGTE.GIF
57DC15E.GIF
58DEQ3.JPEG
59DHS.JPEG
60DM12.GIF
61DM912.GIF
62DR.GIF
63DUNLOP_SYSTEM65.GIF
64DV0312.GIF
65EVERETT_AUDITORIUM.GIF
66EVERETT_ORCH.GIF
67EXP17_SM.GIF
68FBC.JPEG
69FQMS_CALTONS.GIF
70FSC.JPEG
71FSCRT.JPEG
72FSCT.JPEG
73FT74.GIF
74GHSA270.JPEG
75GHSPF140.JPEG
76GHSS335.JPEG
77GHS_BOOMERS_BASS_ROUNDWOUND.GIF
78GHS_SIG_BRONZE.JPEG
79GORE_ELIXIR_PACKAGES.GIF
80GORILLA_SNOT.GIF
81GUITAR_HUMIDIFIER.GIF
82HD-28V.GIF
83HD28.GIF
84HD28LSV.GIF
85HD28VS.GIF
86HJGN-2.JPEG
87HJGN-2BK.JPEG
88HJGN-2GD.JPEG
89HJGN3.JPEG
90HJGN3BK.JPEG
91HJGN3GD.JPEG
92HJGS-1.JPEG
93HJGS-1BK.JPEG
94HJGS-1GD.JPEG
95HJGS3.JPEG
96HJGS3BK.JPEG
97HJGS3GD.JPEG
98HPD41.GIF
99HUMID.JPEG
100HYGRO_THERMO_SMALL.GIF
101INTELLITOUCH_SMALL.GIF
102J1215.GIF
103J1216GT.GIF
104JC16GTE.GIF
105JM.GIF
106KABC.JPEG
107KADJ.JPEG
108KAGR.JPEG
109KAOS.JPEG
110KAPP.JPEG
111KARR.JPEG
112KAYH.JPEG
113KYSERPAIGE.GIF
114KYSER_LIFEGUARD.GIF
115LABELLA.JPEG
116LARRIVEE_L01.GIF
117LEVY_MANDO.GIF
118LJAK_A_GD.JPEG
119LV_B03A.GIF
120LV_D03.GIF
121LV_D0312.GIF
122LV_D05.GIF
123LV_D10.GIF
124LV_L09.GIF
125LV_LV03.GIF
126LV_OM03.GIF
127LV_OM10.GIF
128LV_PARLOR.GIF
129M140BRON.JPEG
130MANDO_SUPERCASE.GIF
131MARTIN_DM.GIF
132MARTIN_POLISH.GIF
133MARTIN_S0.jpe
134MEMORY_THERMO_HYGRO.GIF
135MSP3100B.JPEG
136MSP4100P.JPEG
137MTSseriesRM100m.jpe
138MTSseriesRM50hb.jpe
139NANOWEB_ELECBASS.GIF
140NANOWEB_ELECGUIT.GIF
141NANOWEB_SM.GIF
142OM1.GIF
143OM15.GIF
144OM18V.GIF
145OM21.GIF
146OM28_V.GIF
147P180.jpe
148PAOM03.GIF
149PETERSON_VS1.GIF
150PETROS_BOTTLES.GIF
151PROTEC_PS144.GIF
152PZPL_1.JPEG
153S800.jpe
154S805.jpe
155S904.jpe
156SABINE_AX2000NEW.GIF
157SABINE_AX2000W.GIF
158SEIKO_ST1100.GIF
159SG3805P1CL.jpeg
160SG3805P1GL.jpeg
161SG3805P2GL.jpeg
162SGEBL.jpeg
163SGEBR.jpeg
164SGECL.jpeg
165SGECR.jpeg
166SHUBBDELUXE.GIF
167SILICA_GEL.GIF
168SKB_18_444.GIF
169SPD16K2.GIF
170SPD16R.GIF
171SPOM-16.GIF
172STRAD_CLOTH.GIF
173SULLIVAN_BRIDGE.GIF
174SUMMIT_PACK_BACK.GIF
175SUPER-SENSITIVE_RED_LABEL_-_REDUCED.GIF
176TAILPIECES.GIF
177THOMASTIK_DOMINANT_-_REDUCED.JPEG
178TKL_CASE.GIF
179TKL_DREADNOUGHT.GIF
180Thumbs.db
181VEGA_BANJO.GIF
182VICTOR.GIF
183VICTORBMCAPO.GIF
184WD1000.JPEG
185WD100SL.JPEG
186WD25.JPEG
187WD250.JPEG
188WD250PAN.JPEG
189WD250PP.JPEG
190WD250S.JPEG
191WDE10.JPEG
192WDE10B.JPEG
193WDE11.JPEG
194WDE11B.JPEG
195WDE11G.JPEG
196WDE12.JPEG
197WDE12G.JPEG
198WDE12L.JPEG
199WDE12S.JPEG
200WDE13.JPEG
201WDE13G.JPEG
202WDE13S.JPEG
203WDE13SG.JPEG
204WDE14.JPEG
205WDE14S.JPEG
206WDE15.JPEG
207WDE16.JPEG
208WDE280.JPEG
209WDE3.JPEG
210WDE4.JPEG
211WDE5.JPEG
212WDENDPIN.JPEG
213WDENDPIN_G.JPEG
214WDFBTCR.jpeg
215WDSTTUNE_C.jpeg
216WDSTTUNE_G.jpeg
217WPU100BL.JPEG
218WPU900C.JPEG
219WPU900CR.JPEG
220WPU90BL.JPEG
221WPU90BLH.JPEG
222WPU90BLHR.JPEG
223WPU90BL_R.JPEG
224WPU90CR.JPEG
225WPU90CRHR.JPEG
226WPUCF.JPEG
227WPULJ.JPEG
228WPULJCR.JPEG
229WS9000.jpe
230a509a.gif
231gibf5.jpe
232secondo250.jpe
233sm_gab.jpe
234sm_goldwreath.jpe
235steffey_24.jpe
236SimpleDivX.exe
237COUR.TTF
238logo-no-border.gif
239help_Icon_blue.gif
240websmart-on-roadmap-160x140.gif
241Favicon.ico
2420158399-R1-009-3.jpg
243Blue hills.jpg
244bumba.jpg
245scan1.bmp
246BCD.gif
247BCD logo Blue.jpg
248Ranger Boats.bmp
249Clay's-Choice-Quilt.gif
250Page at a Time Maintcde.tpl
251Logo_RS_1.gif
252scan2.jpg
253img002.jpg
254000C15E.zip
255flag.bmp
256cancel_rd.gif
257no_photo.gif.jpg
258no_photo.gif
259no_photo.jpEG
260pdflaunch
  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 you find this example useful?  Yes  No  Don't Know

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