Uploaded file name is very vital to insert, update and retrieve media or other data. sometimes during uploading files filename contains some special characters (like $%^& etc.) which create complexity. that’s why we try to avoid special characters in our filename in the database. we can remove special characters from the uploaded filename by using a simple regular expression.
If we want to keep some specific special character like “( ) / . % – &” then we just need to change it as follows
preg_replace(‘/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s’,”,$string); [It removes “( ) / . % – &” from filename]