note 72304 added to function.tempnam

From: Date: Fri, 12 Jan 2007 12:47:47 +0000
Subject: note 72304 added to function.tempnam
Groups: php.notes 
Request: Send a blank email to php-notes+get-121577@lists.php.net to get a copy of this message
I want to guarantee that the file will be created in the specified directory or else the function should return FALSE, I have a simple function that works, but I am unsure if its a potential security issue. function dir_tempnam($dir, $prefix) { $real_dir_path = realpath($dir); if (substr($real_dir_path, -1) != '/') $real_dir_path .= '/'; $tempfile = tempnam($real_dir_path, $prefix); $name = basename($tempfile); if(is_file($real_dir_path.$name)) return $name; else { @unlink($name); return FALSE; } } This function returns just the name of the temporary file in the specified directory, or FALSE. Obviously it could return the entire $tempfile, but in my case, I actually want the basename value seperate. ---- Server IP: 203.16.234.20 Probable Submitter: 60.240.112.111 ---- Manual Page -- http://www.php.net/manual/en/function.tempnam.php Edit -- https://master.php.net/note/edit/72304 Del: integrated -- https://master.php.net/note/delete/72304/integrated Del: useless -- https://master.php.net/note/delete/72304/useless Del: bad code -- https://master.php.net/note/delete/72304/bad+code Del: spam -- https://master.php.net/note/delete/72304/spam Del: non-english -- https://master.php.net/note/delete/72304/non-english Del: in docs -- https://master.php.net/note/delete/72304/in+docs Del: other reasons-- https://master.php.net/note/delete/72304 Reject -- https://master.php.net/note/reject/72304 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121577) next »