From 862187d0a5159b6fc734626a4c3bb1fa9bcb650d Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sun, 28 Dec 2014 00:33:12 +0800 Subject: [PATCH] add function __invoke() in File/Upload service --- Westdc/File/Upload.php | 14 ++++++++++++++ Westdc/Reference/Reference.php | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Westdc/File/Upload.php b/Westdc/File/Upload.php index bd5ee6a..052179c 100644 --- a/Westdc/File/Upload.php +++ b/Westdc/File/Upload.php @@ -22,6 +22,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac private $fileName = ""; private $config; + //日期路径模式 const DATETIME_MODEL_YMD = "Y/M/D/"; const DATETIME_MODEL_YM = "Y/M/"; const DATETIME_MODEL_Y = "Y/"; @@ -44,7 +45,20 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac $this->config = $configService->get('file.php'); } + public function __invoke($files,$rootDir = "",$childDir = "",$fileName = "",$dateDirModel = self::DATETIME_MODEL_YMD) + { + $this->upload($files,$rootDir,$childDir,$fileName,$dateDirModel); + } + /** + * 上传文件 + * @param $files 上传文件的信息 e.g.$_FILE['fileData'] + * @param string $rootDir 文件存储的根路径(磁盘物理路径),如果没有设置则从 config/autoload/file.php 中读取 upload 配置 + * @param string $childDir 根路径中的下一级路径,默认为空 + * @param string $fileName 新文件的文件名,如果不指定则设置为新的UUID + * @param string $dateDirModel 年月日目录模式,如果设为 false 则存储时不添加年月日路径,年月日路径在子文件夹中创建,unix和linux中需要开启上传目录的权限,否则无法创建文件夹 + * @return array + */ public function upload($files,$rootDir = "",$childDir = "",$fileName = "",$dateDirModel = self::DATETIME_MODEL_YMD) { if (empty($files) !== false) { diff --git a/Westdc/Reference/Reference.php b/Westdc/Reference/Reference.php index a576692..e0098de 100644 --- a/Westdc/Reference/Reference.php +++ b/Westdc/Reference/Reference.php @@ -111,8 +111,8 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter $configService = $this->serviceManager->get('ConfigService'); $appConfig = $configService->get('application.ini'); - $fileService = $this->serviceManager->get('File/Upload'); - $file_info = $fileService->upload($file,$appConfig['reference_save_path'],"","",$fileService::DATETIME_MODEL_Y); + $fileUploadService = $this->serviceManager->get('File/Upload'); + $file_info = $fileUploadService($file,$appConfig['reference_save_path'],"","",$fileUploadService::DATETIME_MODEL_Y); if(isset($file_info['error']) && !empty($file_info['error'])) {