When customizing image names or file names during uploads, it is necessary to generate larger unique names. It can be done with following php function.
function generateRandomString($len = 80)
{
$base = 'abcdefghjkmnpqrstwxyz123456789';
$max = strlen($base)-1;
$string = '';
while(strlen($string) < $len){
// The mt_rand() function generates a random integer using
// the Mersenne Twister algorithm and
// it is 4 times faster than rand
$string .= $base[mt_rand(0, $max)];
}
return $string;
}
For example: if len is given 20, then the function will return random string of length 20 like this - yjh29cj77qy8nxx2e7zf.
By default the string length is 80.
If larger random number is required to generate then it is same drill. You can use the following function.
function generateNumberString($len = 80)
{
$base = '123456789';
$max = strlen($base)-1;
$string = '';
while(strlen($string) < $len)
$string .= $base[mt_rand(0, $max)];
return $string;
}