PHP function to randomize a file name

I made the function for a web project I was working on, but then didn’t end up using it. All it does is take the given file name, check the file-type and then create a random string as the new file name while keeping the file-type intact. If there is no file-type (ie the file name given is just the name, the function will just return a random string as a new file name

function randomizeFileName( $real_file_name ) {     
        $name_parts = @explode( ".", $real_file_name );     
        $ext = "";     
        if ( count( $name_parts ) > 0 ) {         
                $ext = "." . $name_parts[count( $name_parts ) - 1];     
        return substr(md5(uniqid(rand(),1)), -16) .$ext;

Not much more to say about it really.


About Cameron
I'm a final year Computer Science/Information Systems major. Already finished my BA in Politics/Philosophy. I do web and software freelance on the side, while I finish studying. Hoping to be self-employed by the end of my degree, otherwise off into the real-world I go....

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: