special characters in the filename

10 года 1 день назад #476 от Support
Support создал тему: special characters in the filename
Hello everyone,

at first: thanks for your excellent piece of work!

I used the file field in my component.
There I saw this piece of code:
//Replace any special characters in the filename
$filename = explode('.', $file['name']);
$filename[0] = preg_replace("/[^A-Za-z0-9]/i", "-", $filename[0]);

//Add Timestamp MD5 to avoid overwriting
$filename = md5(time()) . '-' . implode('.',$filename);

I would suggest to change the code to:
//Replace any special characters in the filename
$path_parts = pathinfo($file['name']);
$path_parts['filename'] = preg_replace('/[^A-Za-z0-9]/i', '-', $path_parts['filename']);

//Add Timestamp MD5 to avoid overwriting
$filename = md5(time()) . '-' . $path_parts['filename'] . '.' . $path_parts['extension'];
Otherwise the replacement will not work for these filenames:
this-file-is.s€c!a\.jpg

Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.

Время создания страницы: 0.074 секунд
Работает на Kunena форум

We use cookies so that you can place orders and we can provide a better service. You can control the use of cookies at the individual browser level. If you reject cookies, you may still use our website, but your ability to use some features or areas of our website may be limited.