/** * Get Directory File Information * * Reads the specified directory and builds an array containing the filenames, * filesize, dates, and permissions * * Any sub-folders contained within the specified path are read as well. * * @access public * @param string path to source * @param bool Look only at the top level directory specified? * @param bool internal variable to determine recursion status - do not use in calls * @return array */ function getDirTree($source_dir, $top_level_only = TRUE, $_recursion = FALSE) { static $_filedata = array(); $relative_path = $source_dir; if ($fp = @opendir($source_dir)) { // reset the array and make sure $source_dir has a trailing slash on the initial call if ($_recursion === FALSE) { $_filedata = array(); $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast while (FALSE !== ($file = readdir($fp))) { if (@is_dir($source_dir . $file) and strncmp($file, '.', 1) !== 0 and $top_level_only === FALSE) { get_dir_file_info($source_dir . $file . DIRECTORY_SEPARATOR, $top_level_only, TRUE); } elseif (strncmp($file, '.', 1) !== 0) { $_filedata[$file] = getFileInfo($source_dir . $file); $_filedata[$file]['relative_path'] = $relative_path; } } return $_filedata; } else { return FALSE; } }
<?php require_once '../../global.php'; require_once 'inc/setting.inc.php'; require_once 'inc/smarty.php'; switch ($ac) { default: $rs = $db->select(0, 0, 'tb_wallpaper', '*', '', 'tbid asc'); foreach ($rs as &$v) { $v['s_url'] = getFileInfo($v['url'], 'simg'); } $smarty->assign('wallpaperList', $rs); $rs = $db->select(0, 1, 'tb_member', 'wallpapertype', 'and tbid=' . $_SESSION['member']['id']); $smarty->assign('wallpaperType', $rs['wallpapertype']); $smarty->display('sysapp/wallpaper/index.tpl'); }
$regex_path = "([^\\/]+)"; $regex_prefix = "{$regex_path}\\/{$regex_path}\\/{$regex_path}"; $regexes = array("windows" => "/{$regex_prefix}\\/win32\\/spring_(.*)_minimal-portable.7z\$/", "macosx" => "/{$regex_prefix}\\/osx64\\/[sS]pring_(.*)[_-]MacOSX-.*.zip\$/", "linux" => "/{$regex_prefix}\\/linux32\\/spring_(.*)_minimal-portable-linux32-static.7z\$/", "linux64" => "/{$regex_prefix}\\/linux64\\/spring_(.*)_minimal-portable-linux64-static.7z\$/"); while (count($dirs) > 0) { $cur = array_pop($dirs); $dh = opendir($cur); while (false !== ($entry = readdir($dh))) { if ($entry[0] == '.') { continue; } if ($cur == ".") { $next = $entry; } else { $next = $cur . '/' . $entry; } if (is_dir($next)) { $dirs[] = $next; } else { reset($regexes); while (list($os, $regex) = each($regexes)) { $arr = getFileInfo($os, $regex, $next); if (count($arr) > 0) { $res[] = $arr; } } } } closedir($dh); } $db->close(); echo json_encode($res);
function getCollectionContent($dir, $depth = false, $properties = false) { $directory = dirname($_SERVER['SCRIPT_FILENAME']) . $dir; $files = array(); append_to_log("inside getDirectoryContent, dir: {$directory}"); $handle = opendir($directory); // For all the entries in the directory: while (false !== ($filename = readdir($handle))) { // Skip current and parent dirs ('.' and '..'). if ($filename == '.' or $filename == '..') { continue; } $files[] = getFileInfo($directory, $filename); append_to_log("inside getDirectoryContent, dir: {$directory}, fil: {$filename}"); } return $files; }
/** * 文件处理服务 * @param string $Root,string $cmd,string $target * @return array */ public function mfile($ROOT, $cmd, $target) { switch ($cmd) { case 'init': return getArray('0', 'success', array('root' => getFileInfo('/', $ROOT), 'config' => array())); break; case 'ls': if (isset($_GET['target'])) { $target = $_GET['target']; } else { $target = ''; } $list = listFile($target, $ROOT); return getArray('0', 'success', array('files' => $list)); break; case 'rename': $name = $_GET['name']; if (file_exists($ROOT . $name)) { $res = false; $msg = 'file exist'; } else { $res = rename($ROOT . $target, $ROOT . $name); } if ($res) { return getArray('0', 'success', array('file' => getFileInfo($name, $ROOT))); } else { return getArray('1', $msg ? $msg : 'rename error'); } break; case 'rm': foreach ($target as $key => $path) { if (is_dir($ROOT . $path)) { $res = removeDir($ROOT . $path); } else { $res = unlink($ROOT . $path); } if (!$res) { break; } } if ($res) { return getArray('0', 'success'); } else { return getArray('1', 'romove error'); } break; case 'touch': if (!file_exists($ROOT . $target)) { file_put_contents($ROOT . $target, ''); $res = file_exists($ROOT . $target); } else { $res = false; $msg = 'file exist'; } if ($res) { return getArray('0', 'success', array('file' => getFileInfo($target, $ROOT))); } else { return getArray('1', $msg ? $msg : 'touch error'); } break; case 'mkdir': if (!file_exists($ROOT . $target)) { $res = mkdir($ROOT . $target); } else { $res = false; $msg = 'file exist'; } if ($res) { return getArray('0', 'success', array('file' => getFileInfo($target, $ROOT))); } else { return getArray('1', $msg ? $msg : 'mkdir error', array('file' => getFileInfo($target, $ROOT))); } break; case 'upload': include "Uploader.class.php"; $uploadConfig = array("savePath" => $ROOT . $target, "maxSize" => 200000, "allowFiles" => array(".rar", ".zip", ".7z", "tar", "gz", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", "", ".txt", ".pdf", ".bmp", ".gif", ".jpg", ".jpeg", ".png", ".psd", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".mov", ".wmv", ".mp4", ".webm")); $up = new Uploader("file", $uploadConfig); $info = $up->getFileInfo(); if ($info["state"] == 'SUCCESS') { return getArray('0', 'success', array('file' => getFileInfo($target . $info["name"], $ROOT))); } else { return getArray('1', $info["state"], array('file' => getFileInfo($target . $info["name"], $ROOT))); } break; case 'download': $path = $ROOT . $target; $info = getFileInfo($target, $ROOT); downloadFile($path, $info['name']); break; case 'info': return getArray('0', 'success', array('file' => getFileInfo($target, $ROOT))); break; default: return getArray('1', 'unknow command'); break; } /*switch*/ }
header('Location: ./SampleApp.php'); } else { if (empty($_SESSION['sEmail']) || empty($_SESSION['sPass'])) { header('Location: ./SampleApp.php'); } } $method = $_POST['method']; switch ($method) { case 'getuserinfo': getUserInfo(); break; case 'getpolicyinfo': getpolicyInfo(); break; case 'getfileinfo': getFileInfo(); break; case 'initupload': initUpload(); break; case 'commitupload': commitUpload(); break; case 'downloadfile': downloadFile(); break; case 'renamefile': renameFile(); break; case 'movefile': moveFile();
function thumbnail($fileid) { $thumbsize = 192; global $convertpath, $database, $fileinfo, $output, $imageTypes, $resource, $ghostScript; $fileid = mysql_escape_string($fileid); if (getFileInfo($fileid) && preg_match("{$imageTypes}", $fileinfo['type'])) { $deletefile = ''; if (preg_match("/image\\/jpeg/", $fileinfo['type'])) { $src_img = imagecreatefromjpeg($fileinfo['path'] . '/' . $fileinfo['filename']); } elseif (preg_match("/image\\/png/", $fileinfo['type'])) { $src_img = imagecreatefrompng($fileinfo['path'] . '/' . $fileinfo['filename']); } elseif (preg_match("/application\\/pdf/", $fileinfo['type'])) { $file1 = $fileinfo['path'] . '/' . $fileinfo['filename']; $file2 = $fileinfo['path'] . '/' . $fileinfo['filename'] . 'temp'; #echo "E:/duarte.com/relay/supportapps/gs/gs8.50/bin/gswin32c.exe -q -dNOPAUSE -dBATCH -sDEVICE=jpeg -sOutputFile=\"$file2\" \"$file1\" 2>&1"; $code = "{$ghostScript} -q -dNOPAUSE -dBATCH -dFirstPage=1 -dLastPage=1 -sDEVICE=jpeg -sOutputFile=\"{$file2}\" \"{$file1}\" 2>&1"; #if($resource == true)echo "$code"; $result1 = @exec($code); $src_img = imagecreatefromjpeg($file2); $deletefile = $file2; } elseif (preg_match("/image\\/x-photoshop|image\\/|application\\/postscript/", $fileinfo['type'])) { #image magic coolthings $file1 = $fileinfo['path'] . '/' . $fileinfo['filename']; $file2 = $fileinfo['path'] . "/thumb_{$fileid}.jpg"; $code = "{$convertpath} \"{$file1}\" -render -flatten -resize " . $thumbsize . "x" . $thumbsize . " \"{$file2}\""; #echo "$code"; $result1 = @exec($code); $src_img = imagecreatefromjpeg($file2); $deletefile = $file2; } $old_x = imageSX($src_img); $old_y = imageSY($src_img); if ($old_x > $old_y) { $thumb_w = $thumbsize; $thumb_h = $old_y * ($thumbsize / $old_x); } if ($old_x < $old_y) { $thumb_w = $old_x * ($thumbsize / $old_y); $thumb_h = $thumbsize; } if ($old_x == $old_y) { $thumb_w = $thumbsize; $thumb_h = $thumbsize; } $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); ob_start("output_handler"); imagejpeg($dst_img, '', 70); ob_end_clean(); $thumb = mysql_escape_string($output); $query = "update {$GLOBALS['tablePrefix']}filesystem set thumb=\"{$thumb}\" where id=\"{$fileid}\""; #echo $query; $result = mysql_query($query, $database) || die("angry death"); if ($deletefile > '') { unlink($deletefile); } #imagedestroy($dst_img); #imagedestroy($src_img); } }
/** * 文件夹下文件列表 * @param string $dir,string $root * @return array filelist * */ function listFile($dir, $ROOT) { if ($handle = opendir($ROOT . $dir)) { $output = array(); $dir = $dir[strlen($dir) - 1] == '/' ? $dir : $dir . '/'; while (false !== ($item = readdir($handle))) { if ($item != "." && $item != "..") { $output[] = getFileInfo($dir . $item, $ROOT); } } closedir($handle); return $output; } else { return false; } }
function getFileInfo($str, $mode) { if ($str == '' || is_null($str)) { return ''; } switch ($mode) { case 'path': return dirname($str); break; case 'name': return basename($str, '.' . end(explode(".", $str))); break; case 'ext': return end(explode(".", $str)); break; case 'simg': return getFileInfo($str, "path") . "/s_" . getFileInfo($str, "name") . ".jpg"; break; } }