What are some potential pitfalls of using include() to open and manipulate files in PHP, as seen in the forum thread?

One potential pitfall of using include() to open and manipulate files in PHP is that it can expose sensitive information if the file path is not properly sanitized. To solve this issue, it is recommended to use functions like file_get_contents() or fopen() with appropriate file path validation to prevent directory traversal attacks.

$file_path = "path/to/file.txt";

// Check if the file path is valid before opening it
if (file_exists($file_path)) {
    $file_contents = file_get_contents($file_path);
    // Manipulate the file contents as needed
} else {
    echo "File does not exist.";
}