When saving a file to the server, its name contains characters (see the pictures below). The name of the file sent to the database is displayed in the correct characters.

$date = date("Ymd H:i:s"); $filedate = date("Y\_m\_d\_H\_i\_s", strtotime($date)); $filename = $_POST['name'].'_'.$filedate.''; move_uploaded_file($_FILES['img']['tmp_name'], $Dir.'/'.$filename.'.jpg'); /имя Ρ„Π°ΠΉΠ»Π° Π±ΡƒΠ΄Π΅Ρ‚ Π±ΡƒΠ΄Π΅Ρ‚ искаТСно, Π° ΠΈΠΌΠ΅Π½Π½ΠΎ Ρ‡Π°ΡΡ‚ΡŒ ΠΈΠΌΠ΅Π½ΠΈ $_POST['name'] mysqli_query($CONNECT, "INSERT INTO `load` VALUES ('', '$_POST[name]', '$_POST[category]', 0, 0, '$_SESSION[USER_NAME]', '$_POST[text]', '$date', '$Active', '$num_img', '$num_file', '$filename')"); /Π² Π±Π΄ Π·Π°ΠΏΠΈΡˆΠ΅Ρ‚ΡΡ имя, Ρ‚ΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ ΠΌΡ‹ ΠΈ ΠΎΠΆΠΈΠ΄Π°Π»ΠΈ 

File names in the database:

File Names in Database

File names on the server:

Filenames on the server

Changed the page encoding to UTF-8 - did not help

  • What is the encoding of the tables? - Invision
  • @Invision encoding utf-8 - Gleb Ostrikov
  • Perhaps the solution is: move_uploaded_file ($ _ FILES ['img'] ['tmp_name'], $ Dir. '/'. Iconv ('UTF-8', 'Windows-1251', $ filename). '. Jpg'); and here I understand why we need to change the encoding of $ filename. But still I still can not understand how mysqli_set_charset ($ CONNECT, "utf8") changes the encoding? - Gleb Ostrikov
  • @Invision And maybe, somehow, by default, put mysqli_set_charset ($ CONNECT, "utf8") in the database settings? - Gleb Ostrikov

2 answers 2

Try to force the utf8 encoding as follows (after setting up the connection)

 mysqli_set_charset($CONNECT, "utf8") 
  • Does not work, installed mysqli_set_charset ($ CONNECT, "utf8"), still saves with krakozyabrami. - Gleb Ostrikov

Depends on the server. If it is windows then most likely you need to use win1251 for the file name in the system. But I would recommend adding an additional field to the database for the actual file name in the system and calling the files in the system, for example, md5(uniqid(null, true)) this would allow each file to have a unique name and display the file name from the database.