test2 Posted June 27, 2009 Report Share Posted June 27, 2009 (edited) Tātad problemčiks sekojoš, man ir randfunkcija, kas iedod rand stringu, nosaukumu noteiktai bildei, bet ja nosaukums sakrīt tad bildei ir hanā tā ir baigā problēma man tagad.... function genRand($length=8) { $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $len = strlen($salt); $makepass = ''; mt_srand(10000000*(double)microtime()); for ($i = 0; $i < $length; $i++) $makepass .= $salt[mt_rand(0,$len - 1)]; return $makepass; } To length es esmu uzlicis 60 tagad, bet poļubomu viņš citreiz atļaujas atkārtoties!!! Varbūt es vispār ne to funkciju esmu paņēmis? Edited June 27, 2009 by test2 Quote Link to comment Share on other sites More sharing options...
marcis Posted June 27, 2009 Report Share Posted June 27, 2009 Nu tad pārbaudi, vai tāds fails jau eksistē :) function genRand($extension, $length = 8){ $chars = array_merge(range('a','z'), range('A', 'Z'), range(0, 9)); $str = ''; for($i=0; $i<$length; $i++){ $str.= $chars[array_rand($chars)]; } return file_exists($str.'.'.$extension) ? genRand($extension, $length) : $str; } Quote Link to comment Share on other sites More sharing options...
Klez Posted June 28, 2009 Report Share Posted June 28, 2009 principā nosaukumu var taisīt šādi: function genRand($length=8, $bilde_name) { return substr( md5(time() . $bilde_name), 0, $length); } un būs unikāls nosaukums katrai bildei ... Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted June 28, 2009 Report Share Posted June 28, 2009 kas garantē to, ka md5() pirmie 8 simboli vienmēr būs atšķirīgi? pārbaudīt vai tāds nosaukums jau izmantots vajag jebkurā gadījumā, ja tiec klāt pie visiem failiem, tad kaut ko šitādu do { $filename = getRandomNosaukumuVienalgaArKāduPaņēmienu(); } while(file_exists($filename)); Quote Link to comment Share on other sites More sharing options...
Klez Posted June 28, 2009 Report Share Posted June 28, 2009 tapēc labāk atstāt visus 32 simbolus :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.