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