I'm trying to make a piece of code that will be responsible for deleting an indexed file from the elasticsearch index, I pass with the indexed file md5(file name), to the id value. It is necessary to make sure that when deleting a file from a folder, the deletion code by id (md5) is executed. I wrote part of the script, but I understand that it is incorrect because if there is no file, then md5 will not be created, please help)
<?php
$path = __DIR__ . ("/uploads/Арне.pptx");
$filename = basename($path);
$md5 = md5_file($path);
print($md5); //Передаю переменную md5 в 'id' индексации elasticsearch
//echo 'MD5-хеш файла ' . $filename . ': ' . md5_file($path);
if (empty(md5_file($path))) {//Провожу проверку, если md5 не совпадает с именем файла в папке
$params = [ //Произвожу удаление индекса из ES
'index' => 'bower',
'id' => $md5
];
$respose = $client->delete($params);
} else {
echo '' . ' есть, файл существует';
}
?>