note 93390 added to function.sys-get-temp-dir

From: Date: Mon, 07 Sep 2009 20:11:40 +0000
Subject: note 93390 added to function.sys-get-temp-dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-160281@lists.php.net to get a copy of this message
There's no need to use a random name for the directory for tempnam. Since a file and a directory can't share the same name on the filesystem, we can exploit this and simply use the name of the current file. It is guaranteed that the directory won't exist (because it's a file, of course). Improving on the last post... <?php if ( !function_exists('sys_get_temp_dir')) { function sys_get_temp_dir() { if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); } if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); } if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); } $tempfile=tempnam(__FILE__,''); if (file_exists($tempfile)) { unlink($tempfile); return realpath(dirname($tempfile)); } return null; } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 67.82.157.55 ---- Manual Page -- http://www.php.net/manual/en/function.sys-get-temp-dir.php Edit -- https://master.php.net/note/edit/93390 Del: integrated -- https://master.php.net/note/delete/93390/integrated Del: useless -- https://master.php.net/note/delete/93390/useless Del: bad code -- https://master.php.net/note/delete/93390/bad+code Del: spam -- https://master.php.net/note/delete/93390/spam Del: non-english -- https://master.php.net/note/delete/93390/non-english Del: in docs -- https://master.php.net/note/delete/93390/in+docs Del: other reasons-- https://master.php.net/note/delete/93390 Reject -- https://master.php.net/note/reject/93390 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160281) next »