add function __invoke() in File/Upload service
This commit is contained in:
parent
d21de7cc11
commit
862187d0a5
|
@ -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) {
|
||||
|
|
|
@ -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']))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue