note 66720 added to function.mt-rand

From: Date: Sat, 27 May 2006 04:47:33 +0000
Subject: note 66720 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-112350@lists.php.net to get a copy of this message
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" ?> ---- Server IP: 64.71.164.2 Probable Submitter: 68.227.126.7 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- http://master.php.net/note/edit/66720 Del: integrated -- http://master.php.net/note/delete/66720/integrated Del: useless -- http://master.php.net/note/delete/66720/useless Del: bad code -- http://master.php.net/note/delete/66720/bad+code Del: spam -- http://master.php.net/note/delete/66720/spam Del: non-english -- http://master.php.net/note/delete/66720/non-english Del: in docs -- http://master.php.net/note/delete/66720/in+docs Del: other reasons-- http://master.php.net/note/delete/66720 Reject -- http://master.php.net/note/reject/66720 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112350) next »