diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 59a8d4a3..6c7637dd 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -7,6 +7,7 @@ use Helpers\dbh; use \Files\Files; use Westdc\Visual; use Westdc\Metadata; +use Westdc\Dataimport; class Admin_DataController extends Zend_Controller_Action { @@ -1584,7 +1585,7 @@ class Admin_DataController extends Zend_Controller_Action /* * 导入本地元数据 */ - function importAction() + function Gction() { $md=new MetadataTable(); $thumb=new ThumbnailTable(); @@ -4143,6 +4144,46 @@ class Admin_DataController extends Zend_Controller_Action view::addPaginator($visual->getVisualMetadata(),$this,10); return; } + + /** + * 數據導入 + */ + public function dataimportAction() + { + $this->view->ac = $ac = $this->_getParam('ac'); + + //文件上傳 + if($ac == "upload") { + $upload = new Dataimport\Upload; + $file = $upload($_FILES['FileData']); + + $this->_helper->json($file); + } + + //預處理 + //判斷文件類型,初步識別文件內容 + if($ac == "preprocess"){ + $this->_helper->viewRenderer('dataimport-preprocess'); + + $file = $this->_getParam('file'); + + if(empty($file)) + $this->view->error = "参数错误"; + + if(!file_exists($file)) + $this->view->error = "要导入的文件已不存在,请返回上一步重新上传"; + + if(isset($this->view->error)) + return; + + $this->view->file = $file; + + } + + + + + }//dataimportAction() public function doiAction() { diff --git a/application/admin/views/scripts/data/dataimport-preprocess.phtml b/application/admin/views/scripts/data/dataimport-preprocess.phtml new file mode 100644 index 00000000..f61c7d3a --- /dev/null +++ b/application/admin/views/scripts/data/dataimport-preprocess.phtml @@ -0,0 +1,18 @@ +headTitle($this->config->title->site); +$this->headTitle('后台管理'); +$this->headTitle()->setSeparator(' - '); +?> +
+
+ partial('data/left.phtml'); ?> +
+ +
+

數據導入文件預處理

+
+ + 處理文件:file ?> + +
+
\ No newline at end of file diff --git a/application/admin/views/scripts/data/dataimport.phtml b/application/admin/views/scripts/data/dataimport.phtml new file mode 100644 index 00000000..b31cfe92 --- /dev/null +++ b/application/admin/views/scripts/data/dataimport.phtml @@ -0,0 +1,90 @@ +headTitle($this->config->title->site); +$this->headTitle('后台管理'); +$this->headTitle()->setSeparator(' - '); +$theme = new Theme; +$theme->AppendPlus($this,"jquery-fileupload"); +?> +
+
+ partial('data/left.phtml'); ?> +
+ +
+

數據導入

+
+ + + + 上傳文件 + +
+ +
+
+ \ No newline at end of file diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index bb1277be..77609938 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -1,16 +1,17 @@
\ No newline at end of file diff --git a/application/models/Theme.php b/application/models/Theme.php index 04e7b99e..9e9c386e 100644 --- a/application/models/Theme.php +++ b/application/models/Theme.php @@ -143,6 +143,17 @@ class Theme '/js/lib/highcharts/highcharts-more.js' ) ), + + 'jquery-fileupload' => array( + $this->ScriptKey => array( + '/js/lib/jquery.fileupload/vendor/jquery.ui.widget.js', + '/js/lib/jquery.fileupload/jquery.iframe-transport.js', + '/js/lib/jquery.fileupload/jquery.fileupload.js', + ), + $this->CSSKey => array( + '/js/lib/jquery.fileupload/css/jquery.fileupload.css', + ) + ), /*********谷歌地图*********/ diff --git a/application/module/Westdc/Dataimport/Upload.php b/application/module/Westdc/Dataimport/Upload.php new file mode 100644 index 00000000..4d2eec60 --- /dev/null +++ b/application/module/Westdc/Dataimport/Upload.php @@ -0,0 +1,97 @@ +config = \Zend_Registry::get('config'); + } + + //上传數據 + public function __invoke($file) + { + try{ + if (empty($file) !== false) { + return array("error"=>"请选择要上传的文件"); + } + + if (@is_uploaded_file($file['tmp_name']) === false) { + return array("error"=>"文件上传失败,请重新上传"); + } + + if($file['size'] > 20 * 1024 * 1024) + { + return array('error'=>"文件大小超出限制"); + } + + $ext = $this->getFileTextExt($file['name']); + $filename = $this->gen_uuid().".".$ext; + + if(!preg_match("/(\\/|\\\)$/",$this->config->dataimport->path)) + $save_path = $this->config->dataimport->path . DIRECTORY_SEPARATOR; + else + $save_path = $this->config->dataimport->path; + + $new_filepath = $save_path.$filename; + + if (move_uploaded_file($file['tmp_name'], $new_filepath) === false) { + return array("error"=>"上传失败,请重试"); + } + + return array( + "success" => 1, + "file"=>$new_filepath + ); + + }catch(Exception $e) + { + return array("error"=>$e->getMessage()); + } + } + + //获取文件扩展名 + public function getFileTextExt($file_name) + { + $temp_arr = explode(".", $file_name); + $file_ext = array_pop($temp_arr); + $file_ext = trim($file_ext); + $file_ext = strtolower($file_ext); + return $file_ext; + } + + //获取文件Mime,通过finfo扩展 + public function getFileMime($file_name) + { + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $filetype = finfo_file($finfo, $file_name) ; //文件mime类型 + finfo_close($finfo); + return $filetype; + } + + //文件名uuid + public function gen_uuid() { + return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + // 32 bits for "time_low" + mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), + + // 16 bits for "time_mid" + mt_rand( 0, 0xffff ), + + // 16 bits for "time_hi_and_version", + // four most significant bits holds version number 4 + mt_rand( 0, 0x0fff ) | 0x4000, + + // 16 bits, 8 bits for "clk_seq_hi_res", + // 8 bits for "clk_seq_low", + // two most significant bits holds zero and one for variant DCE1.1 + mt_rand( 0, 0x3fff ) | 0x8000, + + // 48 bits for "node" + mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) + ); + } + +} \ No newline at end of file