Page 291 - Computer Software Application TP - Volume 1
P. 291
COMPUTER SOFTWARE APPLICATION - CITS
// File path
$filePath = ‘my_new_file.txt’;
// Open the file in read mode
$fileHandle = fopen($filePath, ‘r’);
// Check if file opened successfully
if ($fileHandle) {
// File opened successfully, perform operations here
echo “File opened successfully.”;
// Close the file handle
fclose($fileHandle);
} else {
// File opening failed, handle error
echo “Failed to open file.”;
}
?>
</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 6: Opening a File for writing text content
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
276
CITS : IT & ITES - Computer Software Application - Exercise 55