Random filename for uploaded images

This trick was shared by Akash Mahajan.
I am sure you must have observed that large web apps like facebook, orkut or flickr image files usually are long and unique. Its a good practice to always change the name of the image file uploaded to your web application by a third party user.

Here is a small function that will help us do it.

function imgName($imgExtension)
{
return time() . substr(md5(microtime()), 0, 12) . ".".$imgExtension;
}

Lets slice apart the function and see how it works.
It takes a single parameter which is the extension of the image file and a random filename which is 22 characters long is generated. This can be modified according to your needs.