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

COMPUTER SOFTWARE APPLICATION - CITS



           EXERCISE 55 :  Demonstrateon Creating and deleting a file,

                                      Reading and writing text files, working with
                                      directories in PHP, checking for existence

                                      of file, determining file size, opening a file

                                      for writing, reading, or appending, Writing
                                      Data to the file Reading characters



            Objectives

           At the end of this exercise you shall be able to
           •  create and delete files/folders in server using PHP
           •  read and write text files using PHP
           •  determine file size and checking for existence of file using PHP.

           Requirements
           Tools/Materials
                                                               •  PHP
           •   Computer/Laptop with latest configuration
           •   Operating system: windows 10 or 11              •  Text editor
           •  Apache web server                                •  Web browser
           Procedure

           TASK 1: Working with directories
           I  Creating a Directory
              1  Open the text editor
              2  Write the following codes
                           <html>
                           <body>
                         <?php


               $directory_path = ‘example_directory’;
               // Check if the directory doesn’t exist before attempting to create
               if (!is_dir($directory_path))
               {
                         // Create the directory with mkdir()
                         mkdir($directory_path);
                         echo “Directory created successfully: $directory_path”;
               }
               else
               {
                         echo “Directory already exists: $directory_path”;
               }
               ?>
                  </body>
                          </html>
              3  Save the program in C:\Apache24\htdocs in a folder with .php extension
              4  Run the Apache services from windows services
              5  Open the browser and type the following address
                                  http://localhost/foldername/


                                                           269
 CITS : IT & ITES - Computer Software Application - Exercise 54
   279   280   281   282   283   284   285   286   287   288   289