How can a file be opened in read-only mode using PHP?
You can use the fopen() function to open a file in read-only mode. Here is an example code:
$file = fopen("example.txt", "r");
if ($file) {
// 在这里进行读取文件的操作
fclose($file);
} else {
echo "无法打开文件";
}
In the above code, the fopen() function opens the file named example.txt in read-only mode (“r”). If the file is successfully opened, file reading operations can be done within the if statement block. Finally, the file is closed using the fclose() function.
Please remember to replace example.txt in the code with the actual file path and name of the file you want to open.