Rename file on Upload

Hello Community. Thanks for the help.
I am currently using the PHPMAKER with a form that allows me to upload files.
I have always had problems with files that have invalid names such as spaces Ñ tildes and special charactersI do not know if there is a way to overcome this problem, I am currently using the following

// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {
	// Enter your code here
	// To cancel, set return value to FALSE

	// foto
// foto
$NuevoNombre = base64_encode($rsnew['foto']);
$Ext = pathinfo($rsnew['foto'], PATHINFO_EXTENSION);
$rsnew['foto'] = $NuevoNombre.'.'.$Ext;



// Galeria
// Recibo un Array y debo contarlo

$NewFiles = explode(MULTIPLE_UPLOAD_SEPARATOR, $rsnew['galeria']);
$FileCount = count($NewFiles);
for ($i = 0; $i < $FileCount; $i++) {
if ($NewFiles[$i] <> "") {
$file = $NewFiles[$i];
$file_extension = substr(strtolower(strrchr($file, ".")), 1);
$file = base64_encode($file).".".$file_extension;
$NewFiles[$i] = $file;
}
}
$FileName = implode(MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
$rsnew['galeria'] = $FileName;



	return TRUE;
}

It works great except when I edit or update the image.Do you know any way to overcome this?

You may try add this line in server side global code:

Config("UPLOAD_CONVERT_ACCENTED_CHARS", true);

I’ll try tks