PHP File and Directory Operations

Don Alexander Eckford's File and Directory Operations in PHP

Contents of ../docs/text.txt

In this lesson, you will learn about ASP .NET core forms and validations.
Forms are an essential part of any web application, and ASP .NET core provides
a straightforward way to create and handle forms using various features.
You will learn about different types of forms in ASP .NET core, including weekly
typed and strongly typed forms. And how to handle them using model binding.
Additionally, you will learn about form validation in ASP .NET core.
Validation is basically crucial to ensure that user inputs are correct and accurate.
You will learn about server side and client side validations in ASP .NET core, as
well as how to implement custom validation to meet specific requirements.
Overall, this lesson will equip you with the necessary skills to create and handle
forms in your ASP .NET core applications and ensure that the user inputs are valid
and accurate.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.
Appended line of text.

New content appended to ../docs/text.txt.

Current permissions for ../docs/text.txt: 0600

Files in directory ../docs/:

 

CODE FOLLOWS

<?php
// Include the header file (assumed to contain common HTML and styles)
include('includes/header.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP File and Directory Operations</title>
</head>
<body>
<h1>Don Alexander Eckford's File and Directory Operations in PHP</h1>

<?php
$filename 
"../docs/text.txt";
$directory "../docs/";

// Check if the file exists, and read its contents
if (file_exists($filename))
{
    echo 
"<h2>Contents of $filename</h2>";

    
// Open the file for reading
    
$file fopen($filename"r") or die("Cannot open file for reading.");

    
// Read and display the entire file
    
echo "<pre>" fread($filefilesize($filename)) . "</pre>";

    
fclose($file);
}
else
{
    echo 
"<p>File $filename does not exist. Creating and writing to it now...</p>";
    
// Create the file and write initial content
    
file_put_contents($filename"This is the initial content of the file.\n");
}

// Append additional content to the file
file_put_contents($filename"Appended line of text.\n"FILE_APPEND);
echo 
"<p>New content appended to $filename.</p>";

// Set file permissions (read and write only for the owner)
chmod($filename0600);

// Display current permissions of the file
echo "<p>Current permissions for $filename: " substr(sprintf('%o'fileperms($filename)), -4) . "</p>";

// List all files in the directory
if (is_dir($directory))
{
    echo 
"<h2>Files in directory $directory:</h2>";
    
$dirHandle opendir($directory);

    echo 
"<ul>";
    while ((
$file readdir($dirHandle)) !== false)
    {
        if (
$file !== '.' && $file !== '..')
        {
            echo 
"<li>$file</li>";
        }
    }
    echo 
"</ul>";

    
closedir($dirHandle);
}
else
{
    echo 
"<p>Directory $directory does not exist.</p>";
}
?>

</body>
</html>
<?php
// Include the footer file (assumed to contain closing HTML and scripts)
include('includes/footer.php');
?>