add function __invoke() in File/Upload service

This commit is contained in:
Jianxuan Li 2014-12-28 00:33:12 +08:00
parent d21de7cc11
commit 862187d0a5
2 changed files with 16 additions and 2 deletions

View File

@ -22,6 +22,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac
private $fileName = ""; private $fileName = "";
private $config; private $config;
//日期路径模式
const DATETIME_MODEL_YMD = "Y/M/D/"; const DATETIME_MODEL_YMD = "Y/M/D/";
const DATETIME_MODEL_YM = "Y/M/"; const DATETIME_MODEL_YM = "Y/M/";
const DATETIME_MODEL_Y = "Y/"; const DATETIME_MODEL_Y = "Y/";
@ -44,7 +45,20 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac
$this->config = $configService->get('file.php'); $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) public function upload($files,$rootDir = "",$childDir = "",$fileName = "",$dateDirModel = self::DATETIME_MODEL_YMD)
{ {
if (empty($files) !== false) { if (empty($files) !== false) {

View File

@ -111,8 +111,8 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter
$configService = $this->serviceManager->get('ConfigService'); $configService = $this->serviceManager->get('ConfigService');
$appConfig = $configService->get('application.ini'); $appConfig = $configService->get('application.ini');
$fileService = $this->serviceManager->get('File/Upload'); $fileUploadService = $this->serviceManager->get('File/Upload');
$file_info = $fileService->upload($file,$appConfig['reference_save_path'],"","",$fileService::DATETIME_MODEL_Y); $file_info = $fileUploadService($file,$appConfig['reference_save_path'],"","",$fileUploadService::DATETIME_MODEL_Y);
if(isset($file_info['error']) && !empty($file_info['error'])) if(isset($file_info['error']) && !empty($file_info['error']))
{ {