What potential pitfalls should be considered when using PHP to manipulate files?

One potential pitfall when using PHP to manipulate files is the lack of proper error handling, which can lead to unexpected behavior or security vulnerabilities. To mitigate this risk, always check for errors when opening, reading, writing, or closing files, and handle them appropriately.

$file = 'example.txt';

$handle = fopen($file, 'r');

if ($handle === false) {
    die('Error opening file');
}

// Continue with file manipulation

fclose($handle);