我的问题涉及到一个想法,我可以通过比较图片的base64编码字符串来检查它是否已经上传...
例如,用于在数据库中查找重复项...
这个操作可能会很大 - 首先将图像转换为base64,然后使用类似于“strcmp()”的方法进行比较...
不确定这是否有太多意义,但你认为这个想法如何?
这个操作会不会太大了?它的准确度如何?这个想法是否有意义?
我的问题涉及到一个想法,我可以通过比较图片的base64编码字符串来检查它是否已经上传...
例如,用于在数据库中查找重复项...
这个操作可能会很大 - 首先将图像转换为base64,然后使用类似于“strcmp()”的方法进行比较...
不确定这是否有太多意义,但你认为这个想法如何?
这个操作会不会太大了?它的准确度如何?这个想法是否有意义?
function areEqual($firstPath, $secondPath, $chunkSize = 500){
// First check if file are not the same size as the fastest method
if(filesize($firstPath) !== filesize($secondPath)){
return false;
}
// Compare the first ${chunkSize} bytes
// This is fast and binary files will most likely be different
$fp1 = fopen($firstPath, 'r');
$fp2 = fopen($secondPath, 'r');
$chunksAreEqual = fread($fp1, $chunkSize) == fread($fp2, $chunkSize);
fclose($fp1);
fclose($fp2);
if(!$chunksAreEqual){
return false;
}
// Compare hashes
// SHA1 calculates a bit faster than MD5
$firstChecksum = sha1_file($firstPath);
$secondChecksum = sha1_file($secondPath);
if($firstChecksum != $secondChecksum){
return false;
}
return true;
}
$equal = ( md5($image1) == md5($image2)) ? true : false;
md5_file()
。 - AbraCadaver