vendredi 13 octobre 2017

Change imported file encoding in Laravel


After a deep research in the forum, I am posting my problem here, because no topic matched my situation.
I am importing a file(csv or excel) in Laravel, in my controller I am using Input::file('file_name') to get the file.
The user has to possibility to choose his encoding from a select in the interface.
So my problem, is that I want to change the file encoding, to that set by the user.
I used mb_detect_encoding function but I always if I check after, I have the ASCII encoding always...
Here my code:

$encoding = Input::get('encoding');
$importFile = Input::file('import_file');
$enc = mb_detect_encoding($importFile, mb_list_encodings(), true);
if ($enc !== $encoding){
    file_put_contents($importFile->getClientOriginalName(),mb_convert_encoding(\File::get($importFile), $encoding, $enc));
}

Thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire