special characters in the filename
Support
Nouveau membre
Posts: 1
il y a 10 ans 18 heures #476
par Support
special characters in the filename a été créé par Support
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:
I would suggest to change the code to:
Otherwise the replacement will not work for these filenames:
this-file-is.s€c!a\.jpg
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'];
this-file-is.s€c!a\.jpg
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.050 secondes