Issue with File Names Containing "ñ" and Accents in Invalid URLs

QuestionsIssue with File Names Containing "ñ" and Accents in Invalid URLs
gustavo lazaro asked 7 months ago

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!

1 Answers
Abu Ghufran Staff answered 5 months ago

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;
}
_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

16 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?