Page 285 - Computer Software Application TP - Volume 1
P. 285

COMPUTER SOFTWARE APPLICATION - CITS



              6  Click the php file to run  and verify the output









































           II  Listing Files and Directories in a Directory
                 1  Open the text editor
                 2  Write the following codes

                              <html>
                              <body>
                            <?php
                         $directory_path = ‘example_directory’;

                  // Check if the directory exists before listing its contents
                  if (is_dir($directory_path))
                  {
                           // Open the directory
                           $directory_handle = opendir($directory_path);
                           // Read and display the contents

                           echo “Contents of $directory_path:\n”;
                           while (($file = readdir($directory_handle)) !== false)
                                   {
                                     echo $file . “\n”;

                           }
                           // Close the directory handle





                                                           270
                                CITS : IT & ITES - Computer Software Application - Exercise 55
   280   281   282   283   284   285   286   287   288   289   290