在 html 中找不到 Img 源,但在 php 中找到 file_exist

Img src not found in html but file_exist in php

我想上传以高棉语命名的图片。

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

我将这张图片上传到我的服务器并将图片名称存储在数据库中。

当我尝试使用 php 获取此图像时,它什么也没显示,即使该文件存在。

在PHP

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

在HTML

<img src="<?= $img_name; ?>" >

这就是我为数据库设置 UTF-8 所做的工作。

示例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

数据库连接 (PDO)

使用 PDO(注意字符集设置)。

$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']);

数据库连接 (mysqli)

$mysqli = new mysqli('localhost', 'username', 'password', 'database');
$mysqli->set_charset('utf8mb4');