Each file uploaded has 3 names: display name, that you can see on the site, thumbnail and physical file name on the disk.
Use the following code in Add page: Before record added and/or Edit page: Before record updated events.
I documented it so that you can understand the code by yourself.
REMARKS:
You can use any file name extension
The file name can contain dots.
This code snippet use a folder name called "files" to save the uploaded files, *you should change it to fit your needs.
The field name that is using this code snippet is"FIELD_NAME",**you should change it to fit your needs.*
// get information about uploaded files
$fileArray = my_json_decode($values["FIELD_NAME"]);
$newSearchStr = "";
for($i = 0; $i < count($fileArray); $i++)
{
//separating file names and extensions.
$filenameArray = explode('.', preg_replace("/(\.)(?=\S+\.)/", "_", $fileArray[$i]["usrName"]));
//generating the name to use as thumbnail, display and physical name using uniqid()
$filenameArray[0] = uniqid(); //Gets a prefixed unique identifier based on the current time in microseconds.
//getting original file names
$physicalFileName = $fileArray[$i]["name"];
$thumbnailFileName = $fileArray[$i]["thumbnail"];
//updating the new name
$newThumbnailFileName = "files/th-".$filenameArray[0].".".$filenameArray[1];
$newPhysicalFileName = "files/".$filenameArray[0].".".$filenameArray[1];
// renaming physical files on the disk
rename($physicalFileName, getabspath($newPhysicalFileName));
rename($thumbnailFileName, getabspath($newThumbnailFileName));
//updating the new names
$fileArray[$i]["usrName"] = $filenameArray[0].".".$filenameArray[1]; //display name
$fileArray[$i]["name"] = $newPhysicalFileName; //physical name
$fileArray[$i]["thumbnail"] = $newThumbnailFileName; //thumbnail physical name
//
if($i == 0)
{
$newSearchStr = $fileArray[$i]["usrName"].",!";
}else
{
$newSearchStr = $newSearchStr . $fileArray[$i]["usrName"] . ",";
}
}
$newSearchStr = $newSearchStr . "!:sStrEnd";
$fileArray[0]["searchStr"] = $newSearchStr;
// updating values of the fields that stores display and physical file names
$values["FIELD_NAME"] = my_json_encode($fileArray);