-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleaner.php
33 lines (29 loc) · 1002 Bytes
/
cleaner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
header('Content-Type: text/plain');
# target database
$target = $argv[1] ?? $_GET['t'] ?? null;
if ($target == null) die("No target detected!");
require __DIR__ . '/modules/Database.php';
$db = new Database($target);
# global settings
if (isset($argv)) chdir(dirname($_SERVER['PHP_SELF']));
$deletable = 0;
$usersDir = __DIR__ . "/media/$target";
$users = $db->queryUsers();
while ($u = $users->fetchArray()) {
if ($u['id'] == $target) continue;
$mediaDir = "$usersDir/{$u['id']}";
if (!is_dir($mediaDir)) continue;
$photo = str_replace('/', '_', $u['photo']);
$banner = str_replace('/', '_', $u['banner']) . '.jfif';
foreach (scandir($mediaDir) as $med) {
if (!str_contains($med, '_')) continue;
if ($med != $photo && $med != $banner) {
$path = "$mediaDir/$med";
$deletable += filesize($path);
echo "$path\n";
unlink($path);
}
}
}
echo "\n" . ($deletable / 1048576) . ' megabytes removed.';