note 66720 deleted from function.mt-rand by bjori

From: Date: Sat, 27 May 2006 15:20:13 +0000
Subject: note 66720 deleted from function.mt-rand by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-112360@lists.php.net to get a copy of this message
Note Submitter: trukin at gmail dot com Reason: bad code ---- To save files and not overwrite the ones with the same name, you might want to use some function to generate a random number and add it before the end of the last dot (.). Example: <? function seed($limit=5){ $str = "asdfghjklpoiuytrewqzxcvbnm1234567890QA". "ZXWSMXLOEIDKCMVNFJRUGYTHTTTT"; $new = ""; for($a=1; $a<=$limit; $a++){ $new .= substr($str, mt_rand(0, strlen($str)-1), 1); } return $new; } // an example $filename = "dir/name.zip"; $ext = explode(".", $filename); $ext = trim(strtolower($ext[count($ext)-1])); $dir = explode("/", $filename); $newname = str_replace($dir[count($dir)-1], $dir[count($dir)-1].".".seed(4).".zip", $filename); // now newname would be something like "dir/name.Ad93.zip" ?>

« previous php.notes (#112360) next »