0

I want to upload image that it name in Khmer language.

Ex: សង្គ្រាមថ្មលោហិត.jpg.

I uploaded this image to my server and stored the image name in the database.

When I try to fetch this image by using php, it shows nothing, even though the file exists.

In PHP

$sql  = mysqli_query($con_database, "select * from Table where id='ID_NUM' ");
$rs = mysqli_fetch_array($sql);
$img_name = $rs['Column_Image'];

In HTML

<img src="<?= $img_name; ?>" >
Ravoan
  • 3
  • 4
  • rename the image before uploading..... – GYaN Nov 07 '17 at 09:42
  • How are you trying to fetch it? Add the code to your question. – svgrafov Nov 07 '17 at 09:48
  • $sql = mysqli_query($con_database, "select * from Table where id='ID_NUM' "); $rs = mysqli_fetch_array($sql); $img_name = $rs['Column_Image']; In HTML – Ravoan Nov 07 '17 at 09:51
  • Are you able to see the name correctly inserted in the database? – nanocv Nov 07 '17 at 10:24
  • when I inserted to database it name like this **`សង្គ្រាមážáŸ’មលោហិáž.jpg`** and file image in folder also the same. – Ravoan Nov 07 '17 at 10:29
  • Is the database table and database connection using UTF8? – Springie Nov 07 '17 at 12:48
  • @Springie - Yes database table is using UTF8 but I'm not sure about database connection. Can you please tell me how to check my connection using UTF8 or not ? – Ravoan Nov 07 '17 at 14:50
  • https://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf-8-in-my-cnf – Daniel W. Nov 07 '17 at 15:28

1 Answers1

0

This is what I do to set up UTF-8 for a database.

EXAMPLE TABLE

CREATE TABLE my_table 
(
   id    INT UNSIGNED NOT NULL AUTO_INCREMENT ,
   name  VARCHAR(25) NOT NULL,

   PRIMARY KEY(`id`)  

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

DATABASE CONNECTION (PDO)

Using PDO (note the charset setting).

$db_connection = new \PDO("mysql:host=".$db_connection_details['host'].";dbname=".$db_connection_details['database_name'] . ";charset=utf8mb4", $db_connection_details['username'], $db_connection_details['password']);

DATABASE CONNECTION (mysqli)

$mysqli = new mysqli('localhost', 'username', 'password', 'database');
$mysqli->set_charset('utf8mb4');
Springie
  • 718
  • 5
  • 8
  • Thank you Springie! after I set utf8 for database connection, it work properly but for image name still like this **`សង្គ្រាមážáŸ’មលោហិáž.jpg`** while in database show like **`សង្គ្រាមថ្មលោហិត.jpg`** – Ravoan Nov 08 '17 at 13:34
  • Apologies, my example was for PDO, I have added a mysqli example. If it is displaying incorrectly in you HTML you will need to ensure your HTML is output it UTF-8 as well. Here is a great post on it https://stackoverflow.com/questions/279170/utf-8-all-the-way-through/279279#279279 – Springie Nov 08 '17 at 14:12