PHP tmpfile() Function

P
PHP touch() Function
PHP tempnam() Function

In this article, you will learn how to create a temporary file in PHP. The tmpfile() function in PHP creates a temporary file with a unique name in read-write (w+) mode.

This temporary file is automatically deleted when closed or the script ends.

what is the syntax of the TMPFILE function in php?

tmpfile()

examples of the TMPFILE function

Example 1. In this example, we create a temporary file with a unique name in read-write (w+) mode.

<?php
$temp = tmpfile();

fwrite($temp, "Testing, testing.");
//Rewind to the start of file
rewind($temp);
//Read 1k from file
echo fread($temp,1024);

//This removes the file
fclose($temp);
?>
PHP touch() Function
PHP tempnam() Function

Add comment

Tutor Network

Share this

Learn PHP from A to Z