note 98232 added to function.tempnam

From: Date: Thu, 03 Jun 2010 09:31:55 +0000
Subject: note 98232 added to function.tempnam
Groups: php.notes 
Request: Send a blank email to php-notes+get-169841@lists.php.net to get a copy of this message
Beware that if you write your function like Chris in his examples (tempnam with suffix or tmpdir), you may receive unexpected results, since the functions are not atomic - if many processes call the same function at the same time, you may end up with unwanted behavior. If you need your own variant of tempnam, use something like this: <?php function tempnam_sfx($path, $suffix) { do { $file = $path."/".mt_rand().$suffix; $fp = @fopen($file, 'x'); } while(!$fp); fclose($fp); return $file; } // call it like this: $file = tempnam_sfx("/tmp", ".jpg"); ?> You may replace mt_rand() by some other random name generator, if needed. ---- Server IP: 147.32.160.17 Probable Submitter: 78.136.172.48 ---- Manual Page -- http://www.php.net/manual/en/function.tempnam.php Edit -- https://master.php.net/note/edit/98232 Del: integrated -- https://master.php.net/note/delete/98232/integrated Del: useless -- https://master.php.net/note/delete/98232/useless Del: bad code -- https://master.php.net/note/delete/98232/bad+code Del: spam -- https://master.php.net/note/delete/98232/spam Del: non-english -- https://master.php.net/note/delete/98232/non-english Del: in docs -- https://master.php.net/note/delete/98232/in+docs Del: other reasons-- https://master.php.net/note/delete/98232 Reject -- https://master.php.net/note/reject/98232 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169841) next »