/** * 上传目录列表 * @param string $path 目录名 * @return array */ function file_list_upload($path) { $config = C('TMPL_PARSE_STRING'); switch (strtoupper(C('FILE_UPLOAD_TYPE'))) { case 'SAE': $path = str_replace(DS, '/', rtrim($path, DS)); $arr = explode('/', ltrim($path, './')); $domain = array_shift($arr); $filePath = implode('/', $arr); $s = new SaeStorage(); $list = $s->getListByPath($domain, $filePath); $res = array(); while (isset($list['dirNum']) && $list['dirNum']) { $list['dirNum']--; array_push($res, array('type' => 'dir', 'name' => $list['dirs'][$list['dirNum']]['name'], 'path' => ltrim($list['dirs'][$list['dirNum']]['fullName'], 'upload/'), 'size' => '-', 'mtime' => '-', 'url' => '#')); } while (isset($list['fileNum']) && $list['fileNum']) { $list['fileNum']--; array_push($res, array('type' => 'file', 'name' => $list['files'][$list['fileNum']]['Name'], 'path' => ltrim($list['files'][$list['fileNum']]['fullName'], 'upload/'), 'size' => format_bytes($list['files'][$list['fileNum']]['length'], ' '), 'mtime' => date('Y-m-d H:i:s', $list['files'][$list['fileNum']]['uploadTime']), 'url' => ltrim($list['files'][$list['fileNum']]['fullName'], 'upload/'))); } return $res; break; case 'FTP': $storage = new \Common\Plugin\Ftp(); $list = $storage->ls($path); foreach ($list as &$item) { $item['path'] = ltrim($item['path'], UPLOAD_PATH); $item['url'] = str_replace('\\', '/', $item['path']); } return $list; break; default: $path = realpath($path); $path = str_replace(array('/', '\\'), DS, $path); $list = glob($path . DS . '*'); $res = array(); foreach ($list as $key => $filename) { array_push($res, array('type' => is_dir($filename) ? 'dir' : 'file', 'name' => basename($filename), 'path' => ltrim(str_replace(realpath(UPLOAD_PATH), '', $filename), DS), 'size' => format_bytes(filesize($filename), ' '), 'mtime' => date('Y-m-d H:i:s', filemtime($filename)), 'url' => ltrim(str_replace(array(realpath(UPLOAD_PATH), '\\'), array('', '/'), $filename), '/'))); } return $res; } }
/** * 文件删除 * @param string $filename 文件名 * @param string $type 其他参数 * @return bool */ function file_delete($filename, $type = '') { switch (strtoupper(C('FILE_UPLOAD_TYPE'))) { case 'SAE': $arr = explode('/', ltrim($filename, './')); $domain = array_shift($arr); $filePath = implode('/', $arr); $s = new SaeStorage(); return $s->delete($domain, $filePath); break; case 'FTP': $storage = new \Common\Plugin\Ftp(); return $storage->unlink($filename); break; default: return \Think\Storage::unlink($filename, $type); } }