What potential pitfalls should be considered when modifying files with PHP?
When modifying files with PHP, potential pitfalls to consider include security vulnerabilities such as allowing unauthorized access or injection attacks, file permission issues that could lead to unintended file modifications or deletions, and handling errors or exceptions that may occur during the file modification process.
// Example of checking file permissions before modifying a file
$filename = 'example.txt';
if (is_writable($filename)) {
// Perform file modification here
file_put_contents($filename, 'New content');
} else {
echo "File is not writable.";
}