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

COMPUTER SOFTWARE APPLICATION - CITS

































           TASK 6: File download

              •  Open the text editor
              •  Write the following codes
                     <?php


                                     $file_path = ‘path/to/your/file.pdf’;  // Replace with the actual file path

                                          $file_name = ‘downloaded_file.pdf’;   // Optional: Customize the filename   for     download


                        header(‘Content-Type: application/pdf’);  // Set content type based on file extension
                 header(‘Content-Disposition: attachment; filename=”’ . $file_name . ‘”’);  // Force        download
                 header(‘Content-Length: ‘ . filesize($file_path));  // Set file size for better download           management

                               readfile($file_path);  // Read and output the file contents directly
                             // Alternatively, you can use:
                             // echo file_get_contents($file_path);


                                exit();  // Prevent further output

                                ?>
              •  Save the program in C:\Apache24\htdocs in a folder with .php extension
              •  Run the Apache services from windows services
              •  Open the browser and type the following address

                 http://localhost/foldername/
              •  Click the php file to run  and verify the output











                                                           251

                               CITS : IT & ITES - Computer Software Application - Exercise 53
   261   262   263   264   265   266   267   268   269   270   271