經過對論壇的深入研究,我在此處發佈我的問題,因爲沒有與我的情況相符的主題。在Laravel中更改導入的文件編碼
我在Laravel中導入一個文件(csv或Excel),在我的控制器中我使用Input::file('file_name')
來獲取文件。
用戶必須有可能從界面中的選擇中選擇他的編碼。
所以我的問題是,我想改變文件編碼,由用戶設置。
我用mb_detect_encoding
功能,但我始終如果我檢查後,我有ASCII編碼總是...
這裏我的代碼:
$encoding = Input::get('encoding');
$fileContent = \File::get($importFile);
$importFile = Input::file('import_file');
$enc = mb_detect_encoding($fileContent , mb_list_encodings(), true);
if ($enc !== $encoding){
\File::put($importFile,mb_convert_encoding(\File::get($importFile), $encoding, $enc));
}
請不要編輯你的問題,以便我的答案不再有意義。將新代碼或新更新添加爲新的部分。記住你的問題(和我的答案)可能有助於未來的訪問者,如果它沒有任何意義,它不會有幫助。 –
我已經說過檢查更新。 – MosCH