public static function dir($dir, $type = 'both', $extra = false) { $info = array(); $infod = array(); $infof = array(); $dh = opendir($dir); while ($name = readdir($dh)) { if ($name == "." || $name == "..") { continue; } if (is_dir("{$dir}/{$name}") && ($type == 'dir' || $type == 'both')) { if ($extra) { $infod[] = array('id' => $name . '/', 'path' => $dir . $name . '/', 'size' => 'NA', 'created' => filectime("{$dir}/{$name}"), 'modified' => filemtime("{$dir}/{$name}"), 'perms' => fileperms("{$dir}/{$name}"), 'permissions' => File::perms("{$dir}/{$name}")); } else { $infod[] = $name; } } if (is_file("{$dir}/{$name}") && ($type == 'file' || $type == 'both')) { if ($extra) { $infof[] = array('id' => $name, 'path' => $dir . $name, 'size' => filesize($dir . '/' . $name), 'created' => filectime("{$dir}/{$name}"), 'modified' => filemtime("{$dir}/{$name}"), 'perms' => fileperms("{$dir}/{$name}"), 'permissions' => File::perms("{$dir}/{$name}")); } else { $infof[] = $name; } } } closedir($dh); $info = array_merge($infod, $infof); return $info; }
/** * testPermission method */ public function testPermission() { $this->skipIf(DIRECTORY_SEPARATOR === '\\', 'File permissions tests not supported on Windows.'); $dir = TMP . 'tests' . DS . 'permissions' . DS; $old = umask(); umask(02); $file = $dir . 'permission_' . uniqid(); $expecting = decoct(0664 & ~umask()); $File = new File($file, true); $result = $File->perms(); $this->assertEquals($expecting, $result); $File->delete(); umask(022); $file = $dir . 'permission_' . uniqid(); $expecting = decoct(0644 & ~umask()); $File = new File($file, true); $result = $File->perms(); $this->assertEquals($expecting, $result); $File->delete(); umask(0422); $file = $dir . 'permission_' . uniqid(); $expecting = decoct(0244 & ~umask()); $File = new File($file, true); $result = $File->perms(); $this->assertEquals($expecting, $result); $File->delete(); umask(0444); $file = $dir . 'permission_' . uniqid(); $expecting = decoct(0222 & ~umask()); $File = new File($file, true); $result = $File->perms(); $this->assertEquals($expecting, $result); $File->delete(); umask($old); }
/** * testChmod method * * @return void */ public function testChmod() { $this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows'); $path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel'; $Folder = new Folder($path); $subdir = 'test_folder_new'; $new = TMP . $subdir; $this->assertTrue($Folder->create($new)); $this->assertTrue($Folder->create($new . DS . 'test1')); $this->assertTrue($Folder->create($new . DS . 'test2')); $filePath = $new . DS . 'test1.php'; $File = new File($filePath); $this->assertTrue($File->create()); $copy = TMP . 'test_folder_copy'; $this->assertTrue($Folder->chmod($new, 0777, true)); $this->assertEqual($File->perms(), '0777'); $Folder->delete($new); }
private function __advancedFileFind($conditions) { if (empty($this->fileList[1])) { $this->return = array(); return true; } $i = 0; foreach ($this->fileList[1] as $file) { if (in_array($file, $this->ignore)) { continue; } if ($this->recursive > -2) { $Folder = new Folder($this->path); $this->return[$i]['File']['path'] = $Folder->path . DS . $file; $this->return[$i]['File']['relative'] = $this->__relativePath($this->return[$i]['File']['path']); $stat = stat($this->return[$i]['File']['path']); $this->__fileStatus($i, $stat); if ($this->recursive > -1) { $this->return[$i]['File']['accessed'] = date('Y-m-d H:i:s', $stat['atime']); $this->return[$i]['File']['modified'] = date('Y-m-d H:i:s', $stat['mtime']); $this->return[$i]['File']['created'] = date('Y-m-d H:i:s', $stat['ctime']); $File = new File($this->return[$i]['File']['path']); $info = $File->info(); $this->return[$i]['File']['dirname'] = $info['dirname']; $this->return[$i]['File']['name'] = $info['basename']; $this->return[$i]['File']['extension'] = isset($info['extension']) ? $info['extension'] : null; $this->return[$i]['File']['filename'] = $info['filename']; $this->return[$i]['File']['writable'] = $File->writable(); if ($this->recursive > 0) { $this->return[$i]['File']['size'] = $File->size(); $this->return[$i]['File']['owner'] = $File->owner(); $this->return[$i]['File']['group'] = $File->group(); $this->return[$i]['File']['accessed'] = $File->lastAccess(); $this->return[$i]['File']['modidfied'] = $File->lastChange(); $this->return[$i]['File']['charmod'] = $File->perms(); if ($this->recursive > 1) { $this->return[$i]['File']['type'] = filetype($this->return[$i]['File']['path']); $this->return[$i]['File']['md5'] = $File->md5(); $this->return[$i]['File']['Extended'] = stat($this->return[$i]['File']['path']); $i++; continue; } $i++; } $i++; } $i++; } $i++; } return true; }