Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.