php creates temporary files

The files we created before are permanent files.

Creating temporary files is also very useful in our daily project development. Several benefits of creating temporary files:

Delete after finishing writing

No need to maintain the deletion status of this file

For example: I need to transfer the content of A’s file Save it in B and transfer 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 the resource type. The file is deleted when it is closed.

<?php
   //创建了一个临时文件
   $handle = tmpfile();

   //向里面写入了数据
   $numbytes = fwrite($handle, '写入临时文件');

   //关闭临时文件,文件即被删除
   fclose($handle);

   echo  '向临时文件中写入了'.$numbytes . '个字节';
?>


Continuing Learning
||
<?php //创建了一个临时文件 $handle = tmpfile(); //向里面写入了数据 $numbytes = fwrite($handle, '写入临时文件'); //关闭临时文件,文件即被删除 fclose($handle); echo '向临时文件中写入了'.$numbytes . '个字节'; ?>
submitReset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!