Hello ,
We’re facing a recurring issue when attaching files whose names contain special characters like “ñ”, accents (á, é, í, ó, ú), or other symbols. When trying to access these files, the system fails to find them because they generate invalid URLs.
We want to implement a validation step before saving the file to ensure that no special characters cause issues.
What method would you recommend for sanitizing file names before storing them? Would it be better to replace special characters with their non-accented versions, remove them completely, or apply specific encoding?
Thanks in advance for your help!
Hello and Apologies for the delay.
Best is to replace them with non-accent characters, and I found this php function used in wordpress:
https://stackoverflow.com/a/10790734/385377
Best replace to use this function is on_insert / on_update event handler.
// third param to true will treat this function as a filter and perform normal add operation after that.
$e["on_insert"] = array("add_callback", null, true);
$g->set_events($e);
function add_callback($data
{
// for e.g. uploaded file is stored in field 'note'
$upload_file = $data["params"]["note"];
// replace characters
$new_name = replace_accent($upload_file);
// rename on FS
rename($upload_file,$new_name);
// rename in sql data
$data["params"]["note"] = $new_name;
}

