A JM Posted August 4, 2009 Share Posted August 4, 2009 Can someone tell me what this function is doing? This is in regard to file renaming routine. $file = ereg_replace("[^a-zA-Z0-9_.-\[\]()]", "", strtr($file, "()áàâãäéèêëíìîïóòôõöúùûüçÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ ", "[]aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC_")); $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/'; $file = $_FILES['Filedata']['name']; $file = utf8_decode($file); $file = ereg_replace("[^a-zA-Z0-9_.-\[\]()]", "", strtr($file, "()áàâãäéèêëíìîïóòôõöúùûüçÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ ", "[]aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC_")); $file = strtolower($file); $aux_targetFile = str_replace('//','/',$targetPath); $targetFile = str_replace('//','/',$targetPath) . $file; $returnFile = $_FILES['Filedata']['name']; if(file_exists($targetFile)) { while ($ok != true) { if(file_exists($targetFile)) { $ok = false; $rand = rand(1000, 9999); $targetFile = $aux_targetFile . $rand . $file; } else { $ok = true; $file = $rand . $file; } } } move_uploaded_file($tempFile,$targetFile); Link to comment https://forums.phpfreaks.com/topic/168862-what-is-this-function-doing/ Share on other sites More sharing options...
kickstart Posted August 4, 2009 Share Posted August 4, 2009 Hi The strtr part appears to be taking the file name and removing any characters with accents and just replacing them with the non accented version. The ereg part is then replacing any of the non mentioned characters in the resulting file name with nothing (ie, removes them). All the best Keith Link to comment https://forums.phpfreaks.com/topic/168862-what-is-this-function-doing/#findComment-890961 Share on other sites More sharing options...
A JM Posted August 4, 2009 Author Share Posted August 4, 2009 So if I'm in the states I shouldn't have to worry about accented characters correct? Thanks. Link to comment https://forums.phpfreaks.com/topic/168862-what-is-this-function-doing/#findComment-890969 Share on other sites More sharing options...
kickstart Posted August 4, 2009 Share Posted August 4, 2009 Hi Possibly not, but depends what you are dealing with. For example if they were people pictures that they uploaded they could easily have their name as the file name containing accents over letters. All the best Keith Link to comment https://forums.phpfreaks.com/topic/168862-what-is-this-function-doing/#findComment-890973 Share on other sites More sharing options...
A JM Posted August 4, 2009 Author Share Posted August 4, 2009 OK, thanks for the information. A JM, Link to comment https://forums.phpfreaks.com/topic/168862-what-is-this-function-doing/#findComment-890983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.