I am using Laravel and Dropzone.js. Everything's fine until I upload file with a cyrillic name. The file's name in the directory looks like - Приети по специалности_окончателно-нов_0
This is something with the encoding I guess. In php.ini
I set default_charset="UTF-8"
internal_encoding = UTF-8
input_encoding = UTF-8
But the problem is still unsolved. What could it be?
Asked
Active
Viewed 2,661 times
4

Alex
- 485
- 6
- 18
-
Did you check headers? `Content-Type` that is returned by your server ? Are you sure that you return are utf-8? – E_p Mar 01 '16 at 22:21
-
Did you check your file encoding? It may not be UTF-8. – subzeta Mar 01 '16 at 22:21
-
`Content-Type: text/html; charset=UTF-8` well maybe the problem is not in the header – Alex Mar 01 '16 at 22:25
-
@E_p any other ideas? – Alex Mar 01 '16 at 22:29
-
@Alex And you 100% sure that files you return are UTF-8? Could be windows 1251... try output in different content types from PHP just as a check . `text/html; charset=windows-1251` or `text/html; charset=iso-8859-1` see if one of them works. And check what is in your `` tag of your html output – E_p Mar 01 '16 at 22:34
-
@E_p What do you mean by `files you return`? – Alex Mar 01 '16 at 22:37
-
@Alex My bad. Thought it was content going back problem. Did you check headers that are sent with your POST request to a server? – E_p Mar 01 '16 at 22:41
-
@E_p From `Response Headers` -> `Content-Type text/html; charset=UTF-8` and from `Request Headers` -> `Content-Type multipart/form-data; boundary=---------------------------322131509032319` – Alex Mar 01 '16 at 22:44
-
Not response but request. Posted my answer – E_p Mar 01 '16 at 22:52
2 Answers
0
Looks like you need http://php.net/manual/en/book.iconv.php If you have it you can try:
$fileName = iconv("cp1251", "utf-8", $_FILES["upload"]["name"]);
// or
// $fileName = iconv("ISO-8859-1", "utf-8", $_FILES["upload"]["name"]);
$baseDir = '/some/dir/';
move_uploaded_file(
$_FILES["upload"]["tmp_name"],
$baseDir.$fileName
);

E_p
- 3,136
- 16
- 28
-
It's late at night in my country. I'm going to bed. Will check it to tomorrow. Thanks for your time – Alex Mar 01 '16 at 23:03
-
Hey, unfortuantely this doesn't work for me...the filename still looks awful – Alex Mar 02 '16 at 09:12
-
@Alex Try to swap `"cp1251", "utf-8"` -> `"utf-8", "cp1251"`. Did you try `cp1251` and `ISO-8859-1` – E_p Mar 02 '16 at 15:28
0
I can confirm below is working:
header("Content-Type: text/html; charset=utf-8");
if ( 0 < $_FILES['file']['error'] ) {
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
echo 'Error';
}
else {
$baseDir = 'uploads/';
$fn = iconv("utf-8", "cp1251", $_FILES["file"]["name"]);
move_uploaded_file($_FILES['file']['tmp_name'], $baseDir.$fn);
echo 'Success';
}

noszone
- 172
- 9