English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP tmpfile() Function Usage and Example

PHP Filesystem Reference Manual

The tmpfile() function can be used in read-write (w +)mode to create a temporary file with a unique name. For new files, this function can return a file handle similar to that returned by the fopen() function, or false if it fails.

Syntax

resource tmpfile (void)

This function can be used in read-write (w +Create a temporary file with a unique name in the )mode and return the file handle. The file will be automatically deleted when the file is closed (for example, by calling the fclose() function or the file handle returned by tmpfile() function when there are no remaining references) or at the end of the script.

Online Example

<?php
   $temp = tmpfile();
   3codebox!!!!');
   rewind($temp);  //Rewind to the beginning of the file
   echo fread($temp, 1024);  //Read from the file1k
   
   fclose($temp);  //It will delete the file
?>

Output Result

w3codebox!!!!

PHP Filesystem Reference Manual