File Handling in PHP
Read from and write to files using PHP file functions safely.
Jason Wood
Oct 29, 2025
25.8k956
PHP can work with files for logs, uploads, and configs.
Read file
$content = file_get_contents("data.txt");
echo $content;
Write file
file_put_contents("log.txt", "Hello
", FILE_APPEND);
Check if file exists
if (file_exists("data.txt")) {
echo "Found";
}
Security tip
Never allow users to choose file paths directly.
Next: Uploading files from forms.
#PHP#Files#Beginner