当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > fopen() 函数
The fopen() function opens a file or URL.
fopen()函数的作用是:打开文件或URL。
If fopen() fails, it returns FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.
如果fopen()失败,它将返回False并附带错误信息。你可以通过在函数名称职前添加一个“@”来隐藏错误的结果。
fopen(filename,mode,include_path,context) |
Parameter参数 | Description描述 |
---|---|
filename | Required. Specifies the file or URL to open 必要参数。指定需要打开的文件和URL |
mode | Required. Specifies the type of access you require to the file/stream. 必要参数。指定需要访问的文件类型 Possible values:
|
include_path | Optional. Set this parameter to '1' if you want to search for the file in the include_path (in php.ini) as well 可选参数。如果你想在include_path(位于php.ini文件中)搜索,将这个参数设置为“1” |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream 可选参数。指定需要处理的文件内容[context]。Context是一组选项,它是用来修改文本流特征的。 |
Note: When writing to a text file, be sure to use the correct line-ending character! Unix systems use n, Windows systems use rn, and Macintosh systems use r as the line ending character. Windows offers a translation flag ('t') which will translate n to rn when working with the file. You can also use 'b' to force binary mode. To use these flags, specify either 'b' or 't' as the last character of the mode parameter.
注意点:当书写一个文本文件时,确认你使用了正确的行结束符[line-ending]。在Unix系统中,行结束符为“n”;在Windows系统中,行结束符为“rn”;在Macintosh系统中,行结束符为“r”。Windows系统中使用了转义符“t”来输出“n”和“rn”;你还可以使用“b”将其转换二进制模式;这个标记指定了“b”或“t”来作为模式参数的最后一个字符。
<?php $file = fopen("test.txt","r"); $file = fopen("/home/test/test.txt","r"); $file = fopen("/home/test/test.gif","wb"); $file = fopen("http://www.example.com/","r"); $file = fopen("ftp://user:[email protected]/test.txt","w"); ?> |