File size: 1.27Kb
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/system/App.php');
$removeFilesDir = ROOT.'/uploads/tmp/';
$formID = isset($_POST['form_id']) ? intval($_POST['form_id']) : null;
$guestHash = isset($_COOKIE['guest_hash']) ? htmlspecialchars($_COOKIE['guest_hash']) : null;
$me['id'] = (!empty($me) ? $me['id'] : null);
$uploadedImages = glob($removeFilesDir.$formID."_*.{jpg,gif,png,jpeg,bmp}", GLOB_BRACE);
if(!empty($uploadedImages))
{
foreach($uploadedImages as $image)
{
$checkPhoto = $albums->photoByName(basename($image));
if(empty($me['id']) && $checkPhoto['guest_hash'] != $guestHash || !empty($me['id']) && $checkPhoto['user_id'] != $me['id'])
{
$json = ['error' => 1, 'comment' => 'У вас недостаточно прав'];
}
else
{
if(unlink($image) && Base::remove('photos', ['name' => basename($image)]))
{
$json = ['success' => 1, 'comment' => 'Изображения успешно удалены'];
}
else
{
$json = ['error' => 1, 'comment' => 'Ошибка удаления'];
}
}
}
}
else
{
$json = ['error' => 1, 'comment' => 'Изображения не выбраны или не найдены'];
}
echo json_encode($json, JSON_UNESCAPED_UNICODE);
?>