File existence and info checks
📖 Scenario: You are creating a simple PHP script to check if a file exists on the server and get some basic information about it. This is useful when you want to confirm a file is present before working with it.
🎯 Goal: Build a PHP script that checks if a file named example.txt exists, then gets its size and last modified time if it does.
📋 What You'll Learn
Create a variable called
$filename with the value 'example.txt'.Create a variable called
$fileExists that stores whether the file exists using file_exists().If the file exists, create variables
$fileSize and $fileModified to store the file size and last modified time using filesize() and filemtime().Print the results clearly showing if the file exists, and if yes, its size and last modified time.
💡 Why This Matters
🌍 Real World
Checking if files exist and getting their info is common in web apps to avoid errors when opening or processing files.
💼 Career
Many programming jobs require handling files safely and showing file details to users or logs.
Progress0 / 4 steps