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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -