Saturday, February 24, 2007

Rename a file on your hosting server

//
function rename_file_hex($name,$path)
{
@$newname = md5_file($path.$name);
$ext = @substr($path.$name,$lenght-4);
@rename($path.$name,$path.$newname.$ext);
}
//

This PHP function renames a File from your server to a "HEX_name.extension".
So this way, you will have a file with an unique name. You just need to know the name of the file(before it is changed) and the path on the server. The function it is called like this:

< ?php
rename_file_hex("file_name.jpg","file_path"); ? >

No comments: