Mysql νκ΅μ΄ encoding
Mysqlκ³Ό νκΈμ κ°μ΄ μ¬μ©νμλμ λΆνΈν¨
June 27, 2024 β’ Code
νμΌμ μ μ₯ν λ 무쑰건 UTF-8 ν¬λ©§μΌλ‘ μ μ₯μ νλκ² μ’μ.
νκ΅μ΄ νμΌ μ μ₯μ νμΌλͺ μ΄ UTF-8μ΄ μλ Unicode NFD λ²μ μΌλ‘ μ μ₯μ΄ λλ€κ³ ν¨ (commonly used in macOS filesystem). μΆνμ νκ΅μ΄ κ²μμ ν΄λ 맀μΉμ΄ λμ§ μμ.
μμ:
$file = $request->file('uploads');
$originalFileName = $file->getClientOriginalName();
// Convert the filename to UTF-8 encoding
/// νκ΅μ΄ κ²μμ νμΌλͺ
μ΄ UTF-8μ΄ μλ Unicode NFD λ²μ μΌλ‘ μ μ₯μ΄ λλ€κ³ ν¨ (commonly used in macOS filesystem).
/// μΆνμ νκ΅μ΄ κ²μμ ν΄λ 맀μΉμ΄ λμ§ μμ.
if (class_exists('Normalizer') && Normalizer::isNormalized($originalFileName, Normalizer::FORM_C) === false) {
$fileName = Normalizer::normalize($originalFileName, Normalizer::FORM_C);
} else {
$fileName = $originalFileName;
}
$fileSize = $file->getSize();
$log = MasterRightsUploadLogs::create([
'file_name' => $fileName,
'file_size' => $fileSize,
'user_id' => auth()->user()->id,
'status' => 'processing',
]);