How to replace or rename image file name containing umluats or accents on file upload
Hello, as I am based in Europe I have a problem that people using our website and wishing to upload an image often have an umlaut, an accent or an empty space in their image file name such as: märz.jpg or le hôtel.jpg.
While the file will upload and the name will be inserted into the DB, the image will not display due to this problem.
In another thread I am asking about how to rename both the uploaded file and the text that is inserted into the DB with a number.
Another approach would be to remove the offending characters as discussed in the thread (Rejecting File Names with Wrong Characters - 11/26/2012) where Jason Byrnes wrote:
the following example will remove the & \ ' character, you can add others to the array:
<?php
if(isset($_FILES)) {
foreach($_FILES as $k => $v) {
$_FILES[$k]["name"] = str_replace(array("&","\\","'"),"",$_FILES[$k]["name"]);
}
}
?>
----------------
Taking this approach I have added the following code to the top of mage page:
----------
<?php
if(isset($_FILES)) {
foreach($_FILES as $k => $v) {
$_FILES[$k]["exhibition_image"] = str_replace(array("ä","ö","ü","é","à","é","ò","ô"," ","&","\\","'"),"",$_FILES[$k]["exhibition_image"]);
}
}
?>
------------
From the upload form:
<input name="exhibition_image" type="file" id="exhibition_image">
----------
From the upload Server behavior:
$InsertQuery->bindColumn("exhibition_image", "s", "".((isset($_FILES["exhibition_image"]))?$_FILES["exhibition_image"]["name"]:"") ."", "WA_DEFAULT");
---------
Unfortunately, both the uploaded image file as well as the file name text inserted into the DB still have the umlaut.
I am using the WA MySqli extension and WA DataBridge File Manipulation feature.
Any suggestions?
Thanks for your help.