Advertisement
gitlez

YA: Simple File Deletion Through Buttons

Jul 9th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. $cmd = ((isset($_GET['cmd']))? $_GET['cmd'] : '');
  4.  
  5. if( $cmd == 'delete'){
  6.     $file = urldecode($_GET['file']);
  7.     if( unlink($file) ){
  8.         $message = '<h3>File: "' . $file . '" has been removed.</h3>';
  9.     }else{
  10.         $message = '<h3>File Deletion Error. Couldn\'t remove file "' . $file . '"</h3>';
  11.     }
  12. }else{
  13.     $message = '';
  14. }
  15.  
  16. // Get Files in Directory. Obviously you would list your files separately. This being for demo only
  17. $dh = opendir('.');
  18. $filesHTML = '';
  19. while($file = readdir($dh)){
  20.     if( !is_dir($file)){
  21.         $filesHTML .= '<li>' . $file . ' <span style="font-size: 80%;"><input type="button" onclick="window.location=\'?cmd=delete&file=' . urlencode($file) . '\';" value="Delete"></li>';
  22.     }
  23. }
  24.  
  25. ?><!DOCTYPE html>
  26. <html>
  27.     <head>
  28.         <title>Simple File Deletion</title>
  29.     </head>
  30. <body>
  31.     <?php echo $message; ?>
  32.     <p>Please Select A File For Deletion:
  33.         <ul>
  34.             <?php echo $filesHTML; ?>
  35.         </ul>
  36.     </p>
  37. </body>
  38. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement