fopen函数用于打开一个文件或者URL,并返回一个文件句柄,以便对文件进行读写操作。其语法如下:
fopen ( string $filename , string $mode [, bool $use_include_path = FALSE [, resource $context ]] ) : resource|FALSE
其中,$filename表示要打开的文件或者URL的路径,$mode表示打开文件的模式,$use_include_path为可选参数,表示是否在 include_path 中搜索文件,$context为可选参数,表示文件句柄的上下文。
$mode参数有以下几种取值:
示例代码:
$handle = fopen("example.txt", "r");
if ($handle) {
    // 读取文件内容
    $content = fread($handle, filesize("example.txt"));
    echo $content;
    
    // 关闭文件句柄
    fclose($handle);
} else {
    echo "无法打开文件";
}