PHP tmpfile() Function

Definition

The tmpfile() function creates a temporary file with a unique name in read-write (w+) mode.

Syntax

PHP tmpfile() Function has the following syntax.

tmpfile()

Return

Returns a file handle, similar to the one returned by fopen(), for the new file or FALSE on failure.

Note

The temporary file is automatically removed when it is closed with fclose(), or when the script ends.

Example

Create a temporary file and write and read


<?php/*from   w ww. j  a va 2s.c  o m*/
$temp = tmpfile();
fwrite($temp, "from java2s.com");
rewind($temp);//Rewind to the start of file
echo fread($temp,2048);//Read 2k from file
fclose($temp);//This removes the file
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions