if (strlen($fileperms) < 3) { while (strlen($fileperms) != 3) { $fileperms .= '0'; } } $fileperms = substr($fileperms, 0, 3); $fs->chmod($files, eval("return(0{$fileperms});")); } break; case 'stat': $filename = $path; if ($has_files) { $filename = reset($files); } $stat = $fs->stat($filename); $stat['size'] = $fs->formatSize($filename) . 'b'; $_RESULT['file_info'] = $stat; break; case 'create_dir': if (!isset($_REQUEST['dirname']) || !$_REQUEST['dirname']) { throw new sjException($_SYSTEM['i18n']->__('Unable to process request')); } $dirname = trim($_REQUEST['dirname']); if (preg_match('/[\\/:*?<>|\'"]+/', $dirname)) { throw new sjException($_SYSTEM['i18n']->__('File name can not contains following symmbols: \\/:*?<>|"\'')); } if (is_dir($path . $dirname)) { throw new sjException($_SYSTEM['i18n']->__('Unable to create folder. Folder with this name already exists')); } if (!$fs->mkdirs($path . $dirname)) { throw new sjException($_SYSTEM['i18n']->__('Unable to create folder. Permissions denied'));
$page = 1; $limit = $sjConfig['max_files_per_page']; $offset = 0; if (!empty($_REQUEST['page']) && is_numeric($_REQUEST['page']) && $_REQUEST['page'] > 1) { $page = (int) $_REQUEST['page']; $offset = ($page - 1) * $limit + 1; } $fs = new iFilesystem(); $result = $fs->setI18n($_SYSTEM['i18n'])->readDir($realpath, '!r', array('sort' => true, 'offset' => $offset, 'limit' => $limit)); $data = array(); foreach ($result as $file) { $info = $fs->getPathInfo($file); $is_dir = is_dir($file); if ($info['basename'][0] == '.') { $filename = $info['basename']; $extension = ''; } else { $filename = $is_dir ? $info['basename'] : $info['filename']; $extension = !$is_dir && isset($info['extension']) ? $info['extension'] : ''; } $data[] = array('basename' => $info['basename'], 'name' => $filename, 'size' => $is_dir ? '' : $fs->formatSize($file) . 'b', 'modified_at' => $fs->formatDate(filemtime($file)), 'type' => $extension, 'is_dir' => $is_dir, 'mode' => $fs->getMode($file)); } $_RESULT['files'] = array('cur_dir' => $cur_dir ? $cur_dir : '', 'source' => $data); } catch (sjException $e) { if ($_SYSTEM['is_ajax']) { $_RESULT['response']['status'] = 'error'; $_RESULT['response']['msg'] = $e->getMessage(); } else { throw $e; } }
<?php $dir = dirname(__FILE__); $fixtures = $dir . '/../fixtures'; $files = array(); require $dir . '/../../lib/php/model/sfFilesystem.class.php'; require $dir . '/../../lib/php/model/iFilemanager.class.php'; require $dir . '/../../lib/php/model/image.class.php'; $fs = new iFilesystem(); logSection($fs->formatSize($fixtures), '->formatSize("' . realpath($fixtures) . '")'); $file = $fixtures . '/test_file_'; $fs->touch($file); logSection(file_exists($file), 'file touched', 'create'); $files[] = $file; $fs->chmod($file, 0777); logSection($fs->getMode($file) == '777', 'change mode to 0777', 'create'); $fileName = 'this is "bad :file|'; $newFileName = $fs->prepareFilename($fileName); logSection($fileName, 'change filename to "' . $newFileName . '"'); $dir = $fs->readDir($fixtures); $count = count($dir); logSection($count, '(not recursive) number of items in fixtures dir = ' . $count); $dir = $fs->readDir($fixtures, 'r'); $count = count($dir); logSection($count, '(recursive) number of items in fixtures dir = ' . $count); $dir = $fs->readDir($fixtures, 'r', array('flags' => 0)); $count = count($dir); logSection($count, '(recursive) number of files in fixtures dir = ' . $count); $dir = $fs->readDir($fixtures, 'r', array('skip' => '/jpe?g$/i')); $count = count($dir); logSection($count, '(skip jpeg) number of items in fixtures dir = ' . $count);