<?php
/*
This class can be use for Comparing Files
*
*/
/**
* Description of vbinary
* * @author server
*/
class vbinary {
private $files = array();
private $seek;
public $result = array();
public function __construct($files=array()) {
if (is_array($files) && count($files)>=2) {
$this->files = $files;
$max = null;
foreach ($this->files as $max_size) {
if (filesize($max_size) > $max)
$max = filesize($max_size);
}
$this->seek = rand(10, $max);
}else throw new Exception ("Must be more files", 500);
}
public function compare() {
echo "compare Start";
$current = array_shift($this->files);
$keys = array();
$c = 0;
echo $current;
foreach ($keys as $k) {
$c++;
$f = fopen($current, "r");
$keys[] = fread($f, $this->seek - $c);
fclose($f);
}
reset($this->files);
next($this->files);
$c = 0;
foreach ($this->files as $file) {
$fin=new finfo(FILEINFO_MIME);
if ( $fin->file($file) == $fin->file($current)){
$dfi = array();
$f = fopen($file, "r");
foreach ($keys as $value) {
$c++;
$dfi[] = fread($f, $this->seek - $c);
}
fclose($f);
$resul=round((count(array_diff($keys, $dfi)) - (filesize($current) - filesize($file))) / 100);
if ($resul == 0 ) {
// same as current
$this->result[] = 100;
} elseif($resul < 0 ) {
$this->result[] = 0 ;
}else $this->result[]= $resul;
}
}
}
}
?>