What is the purpose of using fopen in PHP and what are the common parameters used?

The purpose of using fopen in PHP is to open a file for reading, writing, or appending data. This function allows you to interact with files on the server, such as reading from a file, writing to a file, or creating a new file. Common parameters used with fopen include the file name/path, mode (r, w, a, etc.), and optional flags.

$file = fopen("example.txt", "r");

if ($file) {
    // File opened successfully, do something with it
    fclose($file);
} else {
    echo "Unable to open file.";
}