PHP tmpfile() Function
In this chapter you will learn:
- Definition for PHP tmpfile() Function
- Syntax for PHP tmpfile() Function
- Return for PHP tmpfile() Function
- Note for PHP tmpfile() Function
- Example - Create a temporary file and write and read
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 j a v a 2 s . 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
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP touch() Function
- Syntax for PHP touch() Function
- Parameter for PHP touch() Function
- Return for PHP touch() Function
- Example - sets the access and modification time of the specified file
Home » PHP Tutorial » PHP File Functions