W3Schools.com

PHP tmpfile() Function


PHP Filesystem Reference Complete PHP Filesystem Reference

Definition and Usage

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

Syntax

tmpfile()


Tips and Notes

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

Tip: See also tempnam()


Example

<?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);
?>

The output of the code above will be:

Testing, testing.


PHP Filesystem Reference Complete PHP Filesystem Reference
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE