note 88607 added to function.file-exists
| From: | fabin dot gnu at gmail dot com | Date: | Sat, 31 Jan 2009 09:03:41 +0000 |
| Subject: | note 88607 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150030@lists.php.net to get a copy of this message | ||
The code can be used to t a filename that can be used to create a new filename.
function generateRandomString($length = 8)
{
$string = "";
//character that can be used
$possible = "0123456789bcdfghjkmnpqrstvwxyz";
for($i=0;$i < $length;$i++)
{
$char = substr($possible, rand(0, strlen($possible)-1), 1);
if (!strstr($string, $char))
{
$string .= $char;
}
}
return $string;
}
function randomFile($folder = '', $extension = '')
{
$folder = trim($folder);
$folder = ($folder == '') ? './' : $folder;
//check if directory exist
if (!is_dir($folder)){ die('invalid folder given!'); }
//generate a filepath
$filepath = $folder . "/" . generateRandomString(128) . $extension;
//check if that filepath already exist, if it exist if generates again
//till if gets one that doesn't exist
while(file_exists($filepath))
{
$filepath = $folder . "/" . generateRandomString(128) . $extension;
}
return $filepath;
}
----
Server IP: 59.162.86.33
Probable Submitter: 61.17.226.215
----
Manual Page -- http://www.php.net/manual/en/function.file-exists.php
Edit -- https://master.php.net/note/edit/88607
Del: integrated -- https://master.php.net/note/delete/88607/integrated
Del: useless -- https://master.php.net/note/delete/88607/useless
Del: bad code -- https://master.php.net/note/delete/88607/bad+code
Del: spam -- https://master.php.net/note/delete/88607/spam
Del: non-english -- https://master.php.net/note/delete/88607/non-english
Del: in docs -- https://master.php.net/note/delete/88607/in+docs
Del: other reasons-- https://master.php.net/note/delete/88607
Reject -- https://master.php.net/note/reject/88607
Search -- https://master.php.net/manage/user-notes.php