I don’t like using files that contain special characters, so I always give a "clean" in the names and etc.
function clearId($id){
$LetraProibi = Array(" ",",",".","'","\"","&","|","!","#","$","¨","*","(",")","`","´","<",">",";","=","+","§","{","}","[","]","^","~","?","%");
$special = Array('Á','È','ô','Ç','á','è','Ò','ç','Â','Ë','ò','â','ë','Ø','Ñ','À','Ð','ø','ñ','à','ð','Õ','Å','õ','Ý','å','Í','Ö','ý','Ã','í','ö','ã',
'Î','Ä','î','Ú','ä','Ì','ú','Æ','ì','Û','æ','Ï','û','ï','Ù','®','É','ù','©','é','Ó','Ü','Þ','Ê','ó','ü','þ','ê','Ô','ß','‘','’','‚','“','”','„');
$clearspc = Array('a','e','o','c','a','e','o','c','a','e','o','a','e','o','n','a','d','o','n','a','o','o','a','o','y','a','i','o','y','a','i','o','a',
'i','a','i','u','a','i','u','a','i','u','a','i','u','i','u','','e','u','c','e','o','u','p','e','o','u','b','e','o','b','','','','','','');
$newId = str_replace($special, $clearspc, $id);
$newId = str_replace($LetraProibi, "", trim($newId));
return strtolower($newId);
}
USE
$target_path = $destination_path . basename( clearId($_FILES['myfile']['name']));
PS.: Depending on the coding of your files it may be necessary to use so clearId(utf8_encode($_FILES['myfile']['name']))
As you have already noticed, it is important that the encoding page and PHP are set correctly (because if the client sends trash, nothing you do on the server will fix). Once done, the proposed solutions should work correctly.
– mgibsonbr
In that question the problem has already been solved, the question is different, but the problem and the answer are the same
– RodrigoBorth