Non recursive chmod script with dir listing


/ Published in: PHP
Save to your folder(s)

Type mode into input than hit Enter


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $dir = dir(dirname(__FILE__));
  4. $files = array();
  5.  
  6. while (false !== $file = $dir->read()) {
  7. // Skip index file and pointers
  8. if(substr($file, 0, 1) == "." OR $file == '.' OR $file == '..') {
  9. continue;
  10. }
  11.  
  12. $stat = stat($file);
  13. $files[] = array('file' => $file, 'uid' => $stat['uid'], 'gid' => $stat['gid'], 'mode' => substr(base_convert($stat['mode'], 10, 8), 2, 4));
  14. }
  15.  
  16. if (isset($_GET['file']) && isset($_GET['chmod']))
  17. {
  18. chmod($files[$_GET['file']]['file'], octdec($_GET['chmod']));
  19. }
  20. ?>
  21.  
  22. <div align="center">
  23. <table border="1" cellspacing="0" cellpadding="5">
  24. <thead>
  25. <tr>
  26. <th>file</th>
  27. <th>uid</th>
  28. <th>gid</th>
  29. <th>permissions</th>
  30. <th>change</th>
  31. </tr>
  32. </thead>
  33. <tbody>
  34. <?php for ($i = 0, $size = count($files); $i < $size; $i++): ?>
  35. <tr>
  36. <td><?php echo $files[$i]['file']; ?></td>
  37. <td><?php echo $files[$i]['uid']; ?></td>
  38. <td><?php echo $files[$i]['gid']; ?></td>
  39. <td><?php echo $files[$i]['mode']; ?></td>
  40. <td><input type="text" onchange="window.location='<?php echo $_SERVER['PHP_SELF']; ?>?file=<?php echo $i; ?>&chmod='+this.value;" value="<?php echo $files[$i]['mode']; ?>" /></td>
  41. </tr>
  42. <?php endfor; ?>
  43. </tbody>
  44. </table>
  45. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.