Welcome Guest, Not a member yet? Register   Sign In
File Upload Library and special characters
#1

Hi,

I have a problem with the file upload library. When I submit a regular file (TEST.pdf) it uploads just fine and the file is stored and accessible as expected as "TEST.pdf".

However whenever I have a special character in the filename (i.e. TÄST.pdf) it uploads just fine and is stored BUT under a different name. TÄST.pdf will be stored as täst.pdf. However in the File Array the name is stored properly as täst.pdf. How can this be and what possible fix do I have for that?
Reply
#2

Are your PHP-files stored as UTF-8?
Reply
#3

(11-05-2018, 12:56 PM)jreklund Wrote: Are your PHP-files stored as UTF-8?
Hi jreklund,

yes UTF-8 is set in the config for CI. First I thought it might be an issue with the server storing the files in ISO instead of UTF-8 but I dont have a problem renaming the file to TÄST.pdf through FTP. I toyed with the idea of adding an a utf-8_decode to the filename in upload.php but changing system files doesnt look like an option.

I guess somewhere down the line the filename which is passed as UTF-8 gets messed with and is stored in ISO. I just cant figure out where and why. The variable is passed around properly. Could the reason be that I am using AJAX to upload the file?
Reply
#4

Just setting the Config to utf-8 will do you no good. Your own Controller need to UTF-8 without BOM for it to be processed correctly.

That can be it, how does your AJAX looks like?
Reply
#5

(11-06-2018, 12:41 PM)jreklund Wrote: Just setting the Config to utf-8 will do you no good. Your own Controller need to UTF-8 without BOM for it to be processed correctly.

That can be it, how does your AJAX looks like?

I will check it out for you. I have to dvelve in the code for that (not by me)
Reply
#6

(This post was last modified: 11-08-2018, 01:12 AM by marwin.)

They used fileinput version 4.3.1

This is how its loaded in the view:

<script>
$(document).ready(function() {

// Fileupload
$("#fileupload").fileinput({
language: 'de',
uploadUrl: '<?php echo $this->config->base_url(); ?>contact/fileupload',
overwriteInitial: false,
showUpload: false,
showClose: false,
dropZoneEnabled: false,
allowedPreviewTypes: ['image'],
<?php if ( ! empty($files)) { ?>
initialPreview: <?php echo json_encode($file_previews); ?>,
<?php } ?>
slugCallback: function(filename) {
return filename.replace('(', '_').replace(']', '_').toLowerCase();
}
}).on("filebatchselected", function(event, files) { $("#fileupload").fileinput("upload");});

// File uploaded
$('#fileupload').on('fileuploaded', function(event, data) {
if (data.response.file_name != null)
{
// Success
console.log(data.response);
// Append input hidden
$("#contact").append('<input data-name="'+data.response.file_name_unreplaced+'" type="hidden" value="'+data.response.file_name+'" name="userfile[]">');
}
});

// File deleted
$('#fileupload').on('filesuccessremove', function(event, id)
{
// Get parent element
var file_name_unreplaced = $('#' + id).children('img').attr('title');

// Remove hidden input
$('input[data-name="'+file_name_unreplaced+'"]').remove();
});
});
</script>

Files are uploaded through <input class="form-control" type="file" id="fileupload" name="userfile[]" value="" multiple>

I cant see anywhere where I could (or should) define UTF-8 again. The locale is set to German but obviously that only affects the icon-names.

What confuses me is that the names are properly read and refered to in the admin mail. They are just stored wrongly on the server in ISO for some reason.

The header of the page in question is set correctly:

<!DOCTYPE html>
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Reply
#7

(This post was last modified: 11-08-2018, 01:14 PM by jreklund.)

Hi, I just re-read everything. And your Javascript looks okay. The file name aren't submitted in the URL.
Can you find the PHP code for the upload part?

Do you get the correct name here in your HTML after upload?
<input data-name="'+data.response.file_name_unreplaced+'" type="hidden" value="'+data.response.file_name+'" name="userfile[]">

Try and delete this part:
Code:
slugCallback: function(filename) {
return filename.replace('(', '_').replace(']', '_').toLowerCase();
}
Reply
#8

(11-08-2018, 01:12 PM)jreklund Wrote: Hi, I just re-read everything. And your Javascript looks okay. The file name aren't submitted in the URL.
Can you find the PHP code for the upload part?

Do you get the correct name here in your HTML after upload?
<input data-name="'+data.response.file_name_unreplaced+'" type="hidden" value="'+data.response.file_name+'" name="userfile[]">

Try and delete this part:
Code:
slugCallback: function(filename) {
return filename.replace('(', '_').replace(']', '_').toLowerCase();
}

Thanks for your help! It's appreciated. THe Filenames are correct in HTML. I will try your suggestion later and report back Smile
Reply
#9

1) you have to need to change file name during upload (encrypted _name)

2) you may change spacial character with a specific string, for example, TEST = t_st

Thanks In Advance
Reply
#10

OK I see what you mean. I have a function to filter special characters for the nice URLs in the setup that I could use.

Let me see if I get this right:

I need to change the name here:

slugCallback: function(filename) {
return filename.replace('(', '_').replace(']', '_').toLowerCase();
}

by running my function over the filename - correct?

My function looks like this though: strtolower(filter_special_chars($variable, TRUE, '-')) - I am pretty new to all of this so how do I port this in the slugCallback?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB