Delete using sudo rm aligned code with play.php

Updated file and directory deletion methods to use 'exec' for sudo commands and handle errors appropriately.
This commit is contained in:
Alexandre
2025-10-12 19:19:41 +02:00
committed by Nachtzuster
parent 2348b1e25e
commit 5ee50c089b
+10 -6
View File
@@ -135,15 +135,19 @@ if (isset($_GET['delete'])) {
$deleted = 0;
foreach ($info['files'] as $fp) {
if (!under_base($fp, $base)) continue;
if (can_unlink($fp) && @unlink($fp)) {
if (exec("sudo rm $fp 2>&1 && sudo rm $fp.png 2>&1", $output)) {
echo "Error - file deletion failed : " . implode(", ", $output) . "<br>";
exit;
}
$deleted++;
foreach ([$fp . '.png', preg_replace('/\.[^.]+$/', '.png', $fp)] as $png) {
if (can_unlink($png)) @unlink($png);
}
foreach ($info['dirs'] as $dir) {
if (!under_base($dir, $base)) continue;
if (exec("sudo rm -r $dir 2>&1", $output)) {
echo "Error - directory deletion failed : " . implode(", ", $output) . "<br>";
exit;
}
}
}
foreach ($info['dirs'] as $dir) { if (under_base($dir, $base)) @rmdir($dir); }
$del = $db->prepare('DELETE FROM detections WHERE Sci_Name = :name');
ensure_db_ok($del);
$del->bindValue(':name', $species, SQLITE3_TEXT);