diff --git a/Westdc/File/Listener/DefaultFileUploadListener.php b/Westdc/File/Listener/DefaultFileUploadListener.php index c6cc3b6..4d172bc 100644 --- a/Westdc/File/Listener/DefaultFileUploadListener.php +++ b/Westdc/File/Listener/DefaultFileUploadListener.php @@ -34,10 +34,32 @@ class DefaultFileUploadListener implements ListenerAggregateInterface $file_data = $e->getParam('file_data'); - return true; + $authService = $this->serviceManager->get('Auth'); - return ['error' => '文件大小超出了限制']; - }, 80); + $data = [ + 'filename' => $file_data['db_path'], + 'filetype' => $file_data['file_type'], + 'filedesc' => $file_data['file_mime'], + 'userid' => $authService->getIdentity('id'), + 'filesize' => $file_data['file_size'], + 'realname' => $file_data['realname'], + ]; + + if(isset($file_data['language'])) + { + $data['language'] = $file_data['language']; + } + + $dbServices = $this->serviceManager->get('Db'); + $dbh = $dbServices->getDbh(); + + $attid = $dbh->insert("attachments" , $data , true); + + if(is_numeric($attid)) + return ['attid' => $attid]; + + return false; + }, 100); } diff --git a/Westdc/File/Upload.php b/Westdc/File/Upload.php index 052179c..81064f7 100644 --- a/Westdc/File/Upload.php +++ b/Westdc/File/Upload.php @@ -21,6 +21,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac private $relativePath = ""; private $fileName = ""; private $config; + private $params; //日期路径模式 const DATETIME_MODEL_YMD = "Y/M/D/"; @@ -47,7 +48,7 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac public function __invoke($files,$rootDir = "",$childDir = "",$fileName = "",$dateDirModel = self::DATETIME_MODEL_YMD) { - $this->upload($files,$rootDir,$childDir,$fileName,$dateDirModel); + return $this->upload($files,$rootDir,$childDir,$fileName,$dateDirModel); } /** @@ -97,12 +98,18 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac } $file_data = array(); + $file_data['file_url'] = $this->getRelativePath() . $this->getFileName(); $file_data['file_size'] = $files['size']; $file_data['db_path'] = $this->getRelativePath() . $this->getFileName(); $file_data['realname'] = $files['name']; $file_data['file_ext'] = $fileService->getFileTextExt($files['name']); - $file_data['file_type'] = $fileService->getFileMime($file_path); + $file_data['file_mime'] = $fileService->getFileMime($file_path); + + if(!empty($file_data) && is_array($file_data)) + { + $file_data = array_merge($file_data,$this->params); + } $results = $this->getEventManager()->trigger('upload.after', $this, compact('file_data')); $cache_data = $results->last(); @@ -210,6 +217,12 @@ class Upload extends AbstractEventManager implements ServiceManagerAwareInterfac } + + public function setParams($params) + { + $this->params = $params; + } + /** * @return string */ diff --git a/Westdc/Reference/Reference.php b/Westdc/Reference/Reference.php index e0098de..87dcf23 100644 --- a/Westdc/Reference/Reference.php +++ b/Westdc/Reference/Reference.php @@ -112,6 +112,7 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter $appConfig = $configService->get('application.ini'); $fileUploadService = $this->serviceManager->get('File/Upload'); + $fileUploadService->setParams(['file_type' => 'literature']); $file_info = $fileUploadService($file,$appConfig['reference_save_path'],"","",$fileUploadService::DATETIME_MODEL_Y); if(isset($file_info['error']) && !empty($file_info['error']))