Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tidy

  • Loading branch information...
commit d9b63932ba320c3c33348250cd0838541deaecf9 1 parent ca2a51a
@tlevine authored
Showing with 25 additions and 22 deletions.
  1. +0 −22 chown.php
  2. +25 −0 rm.php
View
22 chown.php
@@ -1,22 +0,0 @@
-
-<?php
-
-if ($handle = opendir('/path/to/files')) {
- while (false !== ("ntry = readdir($handle))) {
- echo "$entry\n";
- }
- closedir($handle);
-}
-
-// File name and username to use
-// $file_name= "foo.php";
-// $path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
-// $user_name = "root";
-//
-// // Set the user
-// chown($path, $user_name);
-//
-// // Check the result
-// $stat = stat($path);
-// print_r(posix_getpwuid($stat['uid']));
-?>
View
25 rm.php
@@ -0,0 +1,25 @@
+<?php
+// Delete everything in a directory
+$DIR = 'tmp';
+
+function deleteDirectoryContents($dir) {
+ if (!file_exists($dir)) return true;
+ if (!is_dir($dir) || is_link($dir)) return unlink($dir);
+ foreach (scandir($dir) as $item) {
+ if ($item == '.' || $item == '..') continue;
+ if (!deleteDirectoryContents($dir . "/" . $item)) {
+ chmod($dir . "/" . $item, 0777);
+ if (!deleteDirectoryContents($dir . "/" . $item)) return false;
+ };
+ }
+}
+
+
+if ($handle = opendir($DIR)) {
+ while (false !== ($entry = readdir($handle))) {
+ if ($entry == '.' || $entry == '..') { continue; }
+ deleteDirectoryContents($DIR . '/' . $entry);
+ }
+ closedir($handle);
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.