php - Generating unique filename -
i want generate unique filename uploaded files. should 5 characters in length, , have following characters only: abcdefghijklmnopqrstuvwxyz0123456789. code:
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $length = 5; $filename = ''; for($i = 0; $i < $length; $i++) { $filename += $chars[mt_rand(0, 36)]; } echo $filename; but end 1 or 2 character long integers, never string characters. if run code:
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789'; $length = 5; $filename = ''; for($i = 0; $i < $length; $i++) { echo $chars[mt_rand(0, 36)]; } it works fine, , following output: 8iwzf.
what doing wrong here? thanks!
you adding (+=). want concatenate string using dot.
$filename .= $chars[mt_rand(0, 36)];
Comments
Post a Comment