Jump to content

What is this function doing?


A JM

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.