php - 如何使用 php 和 md5 将数据库中存储的图像与用户输入的图像进行比较

标签 php mysql image md5

我想将图像与数据库中存储的图像进行比较..可以使用 md5 吗?我的意思是存储在数据库中的文件是否与原始文件具有相同的 md5 值..?

//the input image
$image1 = $_FILES['image1']['tmp_name'];
$image1 =addslashes(file_get_contents($image1));

//the stored image
$image2=mysqli_fetch_array(mysqli_query($con,"select image from 
civilregistry where nationalnumb=12345678900"));
$image2 = $image2[0];

$image1md5=md5(file_get_contents($image1));
$image2md5=md5(file_get_contents($image2));

if($image1md5==$image2md5)
{echo"compatible";}
else
{echo"not compatible";}

注意:在将图像存储到数据库之前,我使用了addslashes。

最佳答案

不要直接使用 file_get_contents

$image1md5=MD5($image1);
$image2md5=MD5($image2);

并进行比较,您可能会得到正确的比较。

注意:file_get_contents() 函数将读取文件的内容,您可以看到以下引用 URL:https://www.w3schools.com/php/func_filesystem_file_get_contents.asp

关于php - 如何使用 php 和 md5 将数据库中存储的图像与用户输入的图像进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53893279/

相关文章:

php - KnpMenuBundle - 如何为菜单的每个元素设置图标类?

php - dyld:未加载库:/usr/local/lib/libpng16.16.dylib 与 php 相关的任何内容

php - mysql : Join/Relating two tables

php - 我从数据库中提取的图像有时不会在浏览器中显示,但如果我查看源代码,它们就会显示

javascript - 如何调整从其他用户加载的图像的大小,以便在保持尺寸的同时使用 css 设置最大宽度和高度? (HTML/JS/CSS)

php - MySQL - 将秒数舍入到最接近的半分钟

mysql - SQL触发器不是在行上而是在属性上

mysql - 如何使用 CakePHP 将 SQL 查询记录到日志文件

mysql - 使一个表中的记录条目引用另一个表中的多条记录

c - 为 Evas 图像对象设置像素数组数据