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

vaqhlq81  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(359)

我想将一个图像与数据库中存储的图像进行比较。。是否可以使用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。

eit6fx6z

eit6fx6z1#

不要直接使用文件获取内容

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

比较一下,你会得到正确的比较。
注意:file\u get\u contents()函数将读取文件的内容,您可以看到以下参考url:https://www.w3schools.com/php/func_filesystem_file_get_contents.asp

相关问题