Page 287 - Computer Software Application TP - Volume 1
P. 287
COMPUTER SOFTWARE APPLICATION - CITS
2 Write the following codes
<html>
<body>
<?php
$directory_path = ‘example_directory’;
// Check if the directory exists before attempting to delete
if (is_dir($directory_path))
{
// Open the directory
$directory_handle = opendir($directory_path);
// Iterate over the contents and delete files and subdirectories
while (($file = readdir($directory_handle)) !== false)
{
if ($file != “.” && $file != “..”)
{
// Delete files and subdirectories
unlink($directory_path . ‘/’ . $file);
}
}
// Close the directory handle
closedir($directory_handle);
// Delete the directory itself
rmdir($directory_path);
echo “Directory and its contents deleted successfully: $directory_path”;
}
else
{
echo “Directory not found: $directory_path”;
}
?>
</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
272
CITS : IT & ITES - Computer Software Application - Exercise 55