What are the common pitfalls to avoid when working with file and folder manipulation in PHP?

Common pitfalls to avoid when working with file and folder manipulation in PHP include not checking for file existence before manipulating it, not handling file permissions properly, and not sanitizing user input to prevent security vulnerabilities. Example PHP code snippet to check for file existence before manipulation:

$filename = 'example.txt';

if (file_exists($filename)) {
    // Perform file manipulation here
    // For example, reading the file contents or writing to the file
} else {
    echo "File does not exist.";
}