Page 289 - Computer Software Application TP - Volume 1
P. 289
COMPUTER SOFTWARE APPLICATION - CITS
TASK 3: Checking for existence of file
1 Open the text editor
2 Write the following codes
<html>
<body>
<?php
// Specify the file name
$fileName = ‘my_new_file.txt’;
// Check if the file exists
if (file_exists($fileName))
{
// File exists, display a success message
echo “File ‘$fileName’ exists.”;
}
else
{
<?php
// File does not exist, display an error message
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 4 : Determining file size
1 Open the text editor
2 Write the following codes
<html>
<body>
274
CITS : IT & ITES - Computer Software Application - Exercise 55