Don Alexander Eckford's Code for Read File:

File found!
File is readable -- reading the file.

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.

 

CODE FOLLOWS

<?php
// Include the header file (assumed to contain common HTML, CSS, and scripts)
include('includes/header.php');

// Enable error reporting to display all errors and warnings during development
error_reporting(E_ALL);

echo(
"<h1>Don Alexander Eckford's Code for Read File:</h1>");

// Define the file path (relative path to the text file)
$myFile '../docs/text.txt';

// Check if the file exists
if (file_exists($myFile))
{
    echo(
'File found! <br>');

    
// Attempt to open the file for reading
    
$handle fopen($myFile'r');
    if (
$handle)
    {
        echo(
'File is readable -- reading the file. <br><br>');

        
// Read the entire contents of the file
        
$content fread($handlefilesize($myFile));

        
// Close the file handle after reading
        
fclose($handle);

        
// Convert newlines in the file content to HTML <br> tags for better formatting
        
$content nl2br($content);

        
// Check if the file content is empty or contains only whitespace
        
if (empty(trim($content)))
        {
            echo 
"<p>The file is empty.</p>";
        }
        else
        {
            echo 
"<p>$content</p>";  // Display the file content if it's not empty
        
}
    }
    else
    {
        
// Error message if the file cannot be opened
        
echo("Cannot read the $myFile <br>");
    }
}
else
{
    
// Error message if the file does not exist
    
echo('File NOT found! <br>');
}

// Include the footer file (assumed to contain closing HTML, scripts, etc.)
include('includes/footer.php');
?>