Такого не может быть(если только один случай из лярда)
Раз хеш одинаковый то хоть как файл переименуй он один и тот же останется. Не давно картинки так переделывал, я те пример скину, а ты сам разбирайся
example (+/-)
if (!empty($_FILES['file'])) {
$upload = Core\Upload::factory('loads', __dir__ . '/../');
$upload->file($_FILES['file']);
$validation = new validation;
// check name leigth and mime type
$upload->callbacks($validation, array('check_name_length','check_mime_type'));
// set max. file size (in mb)
$upload->set_max_file_size(2);
$fileformat = strrchr($_FILES['file']['name'], '.');
if (isset($_POST['auto']) || preg_match('/[а-яё]+/i', $_FILES['file']['name'])) {
$filesme = uniqid('image_') . $fileformat;
} else {
$filesme = $_FILES['file']['name'];
}
$hash_file = md5_file($_FILES['file']['tmp_name']);
if (!$file_name = $db->query('SELECT `file` FROM `pic_files` WHERE `hash_file`=?', [$hash_file])->el()) {
$results = $upload->upload($filesme);
} else {
$filesme = $file_name;
$results['status'] = true;
$err = 'Такой файл уже загружен, ваш файл переименован!';
}
}
if ($results['status']) {
$id_cat = intval($_POST['cat']);
$file_id = $db->query(
'INSERT INTO `pic_files` (`id_cat`, `file`, `hash_file`, `time_d`, `time_s`, `time`, `id_user`) VALUES(?i, ?, ?, ?i, ?i, ?i, ?i)',
[$id_cat, $filesme, $hash_file, time(), time(), time(), $user['id']])->id();
echo '<div class="msg">Файл успешно добавлен</div>';
} else {
$err = $results['errors'];
}
Хеш существующих файлов можно записать в таблицу как то так
select `name` /* или ай-ди в зависимости как у тебя файлы на диске названы */ from tbl
while () {
// тут пройти по файлам с $hash = md5_file('path_to_file');
update tbl set hash=$hash where id;
}