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

COMPUTER SOFTWARE APPLICATION - CITS



                                             // Specify the file name
                         $fileName = ‘my_new_file.txt’;



                         //  Check if the file exists
                         if (file_exists($fileName))
                         {
                                 // Get the file size in bytes
                                 $fileSizeBytes = filesize($fileName);

                                 //  Convert the file size to kilobytes or megabytes
                                 $fileSizeKB = $fileSizeBytes / 1024; // Bytes to Kilobytes
                                 $fileSizeMB = $fileSizeKB / 1024;    // Kilobytes to Megabytes
                                 //  Display the file size

                                 echo “File ‘$fileName’ has a size of $fileSizeBytes bytes,
              $fileSizeKB KB, or $fileSizeMB MB.”;
                         }
                         else

                         {
                                 // Display an error message if the file does not exist
                                 echo “Error: File ‘$fileName’ does not exist.”;
                         }
                   ?>

                     </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/
           6  Click the php file to run  and verify the output














           TASK 5: Opening a File for reading
           1  Open the text editor
           2  Write the following codes
                           <html>

                           <body>
                <?php


                                                           275
 CITS : IT & ITES - Computer Software Application - Exercise 55  CITS : IT & ITES - Computer Software Application - Exercise 55
   285   286   287   288   289   290   291   292   293   294   295