Several benefits of creating temporary files:
1. Delete them after use
2. There is no need to maintain the deletion status of this file
For example: I It is necessary to transfer the file contents of A to B and the file contents of B to C.
Just like in real life, I can first use a temporary bottle to fill B's water, and then write A's data into B. Add the water from the temporary bottle to C.
Let’s learn this function:
resource tmpfile ( )
Function: Create a temporary file and return resources type. The file is deleted when it is closed.
<?php //创建了一个临时文件 $handle = tmpfile(); //向里面写入了数据 $numbytes = fwrite($handle, '写入临时文件'); //关闭临时文件,文件即被删除 fclose($handle); echo '向临时文件中写入了'.$numbytes . '个字节'; ?>