$protected = ['index.php', '.htaccess'];

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['files'])) {
$results = [];
foreach ($_POST['files'] as $file) {
$file = basename($file);
$path = __DIR__ . '/' . $file;

if (in_array($file, $protected)) {
$results[$file] = '⛔ Protected';
} elseif (is_file($path) && unlink($path)) {
$results[$file] = '✅ Deleted';
} else {
$results[$file] = '❌ Failed or Not Found';
}
}
}

$files = array_values(array_filter(scandir(__DIR__), function ($f) {
return is_file(__DIR__ . '/' . $f);
}));

<!DOCTYPE html>


<meta charset="UTF-8">
File Manager + Search<title>File Manager + Search</title>
<style>
body {font-family: Arial; padding:20px; background:#111; color:#fff}
.card {background:#1a1a1a; padding:15px; border-radius:12px; margin-bottom:15px}
.search {width:100%; padding:8px; border-radius:8px; border:none; margin-bottom:10px}
.btn {background:#e60000; color:#fff; border:none; padding:10px 18px; border-radius:8px; cursor:pointer}
.file-item {margin:4px 0; padding:4px 0; border-bottom:1px dashed #333}
</style>



<div class="card">

Files in Current Folder





<div id="fileList">
foreach ($files as $file):
<div class="file-item" data-name="= strtolower($file) ">
<label>

= $file
</label>
</div>
endforeach;
</div>



<button class="btn" type="submit">Delete Selected</button>

</div>

if (isset($results)):
<div class="card">

Results


foreach ($results as $file => $status):
<p><strong>= $file :</strong> = $status </p>
endforeach;
</div>
endif;

<script>
document.getElementById("search").addEventListener("input", function() {
let q = this.value.toLowerCase();
document.querySelectorAll("#fileList .file-item").forEach(item => {
item.style.display = item.dataset.name.includes(q) ? "block" : "none";
});
});
</script>