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

COMPUTER SOFTWARE APPLICATION - CITS



            TASK 2: Creating a file

           1  Open the text editor
           2  Write the following codes
                           <html>
                           <body>
                         <?php

                            // Specify the file name and path:
               $filename = “my_new_file.txt”;  // Modify with desired name and location
               // Open the file in write mode (creates the file if it doesn’t exist):
               $handle = fopen($filename, “w”) or die(“Unable to open file!”);

               // Write content to the file:
               $content = “This is the content of my new file!”;
               fwrite($handle, $content);
               // Close the file:
               fclose($handle);
               // Optional: Display a success message:
               echo “File created successfully!”;
               ?>
                  </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








































                                                           273
 CITS : IT & ITES - Computer Software Application - Exercise 55  CITS : IT & ITES - Computer Software Application - Exercise 55
   283   284   285   286   287   288   289   290   291   292   293