Home>Article>Backend Development> How does PHP create temporary files in read-write (w+) mode?

How does PHP create temporary files in read-write (w+) mode?

藏色散人
藏色散人 Original
2019-04-04 14:38:51 3689browse

Thetmpfile()function in PHP is a built-in function used to create a temporary file with a unique name in read-write(w)mode.

Files created using thetmpfile() functionare automatically deleted when closed usingfclose()or when there are no remaining references to the file handle.

The temporary file created using thetmpfile()function will also be deleted at the end of the script.

tmpfile()The function does not accept any parameters, it returns a file handle similar to the file handle returned by fopen(), for new files or returns FALSE on failure.

Syntax:

tmpfile()

Return value:

Returns the file handle of the new file on success, and returns FALSE on failure.

Errors And Exception:

1. When the temporary file is closed using fclose(), or when the script ends, the temporary file will be automatically deleted.

2. The function of the tmpfile() function is to return a Boolean value False, but many times it returns a non-Boolean value, and the calculation result of this value is False.

Example 1:


      

Output:

1

Example 2:


      

Output:

GeeksforGeeks

Related recommendations: "PHP Tutorial"

The above is the detailed content of How does PHP create temporary files in read-write (w+) mode?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn