Advertisement
ssaidz

delte.php - delete all files on folder with confirmation

Nov 29th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. $folder = 'uploads'; // Ganti dengan path folder yang diinginkan
  3.  
  4. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  5. // Jika tombol submit diklik dengan konfirmasi
  6. if (isset($_POST['confirm'])) {
  7. // Menghapus semua file dalam folder
  8. $files = glob($folder . '/*'); // Mengambil daftar file dalam folder
  9. foreach ($files as $file) {
  10. if (is_file($file)) {
  11. unlink($file); // Menghapus file
  12. }
  13. }
  14. echo "Semua file dalam folder telah dihapus.";
  15. } else {
  16. echo "Penghapusan dibatalkan.";
  17. }
  18. }
  19. ?>
  20.  
  21. <!DOCTYPE html>
  22. <html>
  23. <body>
  24.  
  25. <h2>Konfirmasi Penghapusan File</h2>
  26. <p>Anda yakin ingin menghapus semua file dalam folder?</p>
  27.  
  28. <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  29. <input type="submit" name="confirm" value="Ya, Hapus Semua File">
  30. <input type="submit" name="cancel" value="Batal">
  31. </form>
  32.  
  33. </body>
  34. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement