The usage of fopen function in php is "fopen(filename, mode, include_path, context)". The fopen() function is used to open a file or URL. If it fails, it returns false with an error message.
The operating environment of this article: windows10 system, php7, thinkpad t480 computer.
Let’s first take a brief look at the definition and return value of the fopen() function.
The fopen() function is used to open a file or URL. If the fopen() function fails to open, it will return FALSE with an error message. Of course, we can hide the error output by adding a '@' in front of the function name.
Next let’s take a look at its syntax:
fopen(filename,mode,include_path,context)
Parameter introduction:
filename: Specifies the file or URL to be opened.
mode: Specifies the type of access required to the file/stream.
include_path: Optional, if you also need to retrieve files in include_path, you can set this parameter to 1 or TRUE.
context: Optional, specifies the environment of the file handle. Context is a set of options that can modify the behavior of the stream.
Finally let us take a look at an example of using the fopen() function:
<?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:password@example.com/test.txt","w"); ?>
Recommended learning: php training
The above is the detailed content of What is the usage of fopen function in php. For more information, please follow other related articles on the PHP Chinese website!