Theory
File I/O
PHP 8.3.8
Web Features

File I/O

Topic 10 of 13
PHP
<?php
// Read entire file
$content = file_get_contents('data.txt');

// Write / overwrite
file_put_contents('log.txt', "Entry\n");

// Append
file_put_contents('log.txt', "New line\n", FILE_APPEND);

// Read lines into array
$lines = file('data.txt', FILE_IGNORE_NEW_LINES);

// File info
file_exists('file.txt');
is_file('file.txt');
filesize('image.jpg');
pathinfo('/path/to/file.txt');  // dirname, basename, ext

// Directory operations
mkdir('uploads', 0755, true);  // recursive
scandir('.');
glob('*.php');
rename('old.txt', 'new.txt');
unlink('temp.txt');           // delete
copy('src.txt', 'dst.txt');