PHP File I/O
Reading Files
// Read entire file
$content = file_get_contents("data.txt");
// Read line by line
$handle = fopen("data.txt", "r");
while (($line = fgets($handle)) !== false) {
echo $line;
}
fclose($handle);
Writing Files
file_put_contents("output.txt", "Hello, World!");
// Append mode
$handle = fopen("log.txt", "a");
fwrite($handle, "New entry
");
fclose($handle);
File Functions
file_exists($path); // Check if file exists
filesize($path); // Get file size
unlink($path); // Delete file
rename($old, $new); // Rename/move