PHP Fundamentals

Learn PHP programming from scratch, including variables, functions, arrays, and object-oriented programming.

beginner Backend Development 6 hours

Chapter 10: Working with Files

Chapter 10 of 15

Chapter 10: Working with Files

10.1 Reading Files

$content = file_get_contents("file.txt");
$lines = file("file.txt");  // Read into array

10.2 Writing Files

file_put_contents("file.txt", "Hello, World!");
$file = fopen("file.txt", "w");
fwrite($file, "Content");
fclose($file);

10.3 File Operations

file_exists("file.txt");    // Check if file exists
is_file("file.txt");        // Check if it's a file
is_dir("folder");           // Check if it's a directory
unlink("file.txt");         // Delete file