$files = arrray_flip(scandir('path/to/storage'));
$stmt = mysqli_query($connect, "SELECT name FROM images");
while($row = mysqli_fetch_assoc($stmt)) {
unset($files[$row['name']]);
}
foreach(array_keys($files) as $file) {
unlink('path/to/storage/'.$file);
}
class Redirect {
private static $url;
public static function to($url) {
self::$url = $url;
return new self;
}
public function withMessage($message, $type = 'error') {
$_SESSION[$type] = $message;
return $this;
}
public function __destruct() {
if(self::$url !== null) {
header('location: '.self::$url);
exit;
}
}
}
Redirect::to('/test')->withMessage('test'); //Перенаправит на /test и запишет в сессию значение test с ключем error
Redirect::to('/test'); //Обычное перенаправление