note 110679 added to function.tmpfile
| From: | ssandor | Date: | Thu, 22 Nov 2012 08:32:28 +0000 |
| Subject: | note 110679 added to function.tmpfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192071@lists.php.net to get a copy of this message | ||
Beware that PHP's tmpfile is not an equivalent of unix' tmpfile.
PHP (at least v. 5.3.17/linux I'm using now) creates a file in /tmp with prefix
"php", and deletes that file on fclose or script termination.
So, if you want to be sure that you don't leave garbage even in case of a fatal error, or
killed process, you shouldn't rely on this function.
Use the classical method of deleting the file after creation:
<?php
$fn = tempnam ('/tmp', 'some-prefix-');
if ($fn)
{
$f = fopen ($fn, 'w+');
unlink ($fn); // even if fopen failed, because tempnam created the file
if ($f)
{
do_something_with_file_handle ($f);
}
}
?>
----
Server IP: 95.130.168.26
Probable Submitter: 94.53.199.174
----
Manual Page -- http://www.php.net/manual/en/function.tmpfile.php
Edit -- https://master.php.net/note/edit/110679
Del: integrated -- https://master.php.net/note/delete/110679/integrated
Del: useless -- https://master.php.net/note/delete/110679/useless
Del: bad code -- https://master.php.net/note/delete/110679/bad+code
Del: spam -- https://master.php.net/note/delete/110679/spam
Del: non-english -- https://master.php.net/note/delete/110679/non-english
Del: in docs -- https://master.php.net/note/delete/110679/in+docs
Del: other reasons-- https://master.php.net/note/delete/110679
Reject -- https://master.php.net/note/reject/110679
Search -- https://master.php.net/manage/user-notes.php