/** * * @todo getInstance */ public function upload() { // if($file['size'] > static:$maxFileSize){ //$errorMessage = "Error: File is too large. File must be smaller than 10 MB"; // } if (!$this->is_allowed_file_type($this->mimeType)) { return false; } $this->rename(); $file = new File(array('fileName' => $this->fileName, 'name' => $this->name, 'path' => $this->getFileVersionDirectory()), true); $file->save(); return $file->getInstance(); }
public function excel_out() { $table_name = strtolower($_REQUEST['table_name']); $tableInfo = $this->CM('cm_table')->where('table_name="' . $table_name . '"')->find(); $condition['table_id'] = $tableInfo['table_id']; $condition['is_excel_out'] = 1; $tableExcelColumnInfo = $this->CM('cm_table_column')->where($condition)->order('excel_out_sort ASC')->select(); vendor('Form.Excel.PHPExcel'); $objExcel = new PHPExcel(); $objWriter = new PHPExcel_Writer_Excel2007($objExcel); $objProps = $objExcel->getProperties(); $objExcel->setActiveSheetIndex(0); $objActSheet = $objExcel->getActiveSheet(); $index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); foreach ($tableExcelColumnInfo as $key => $value) { $objActSheet->setCellValue($index[$key] . '1', $value['column_desc']); } $allRecord = $this->CM($table_name)->select(); foreach ($allRecord as $recordKey => $Row) { foreach ($Row as $cellKey => $cell) { foreach ($tableExcelColumnInfo as $key2 => $columnInfo) { if ($columnInfo['column_name'] == $cellKey) { //echo $index[$key2].($recordKey+2).'---'.$cell.'<br>'; $value = ''; $excel_outArr = unserialize($columnInfo['excel_out_map']); if ($excel_outArr['map_type'] == 'origin') { $value = $cell; } if ($excel_outArr['map_type'] == 'list') { $list_id = $excel_outArr['map_list_id']; $res = $this->CM('cm_list_item')->where('list_id=' . $list_id)->select(); foreach ($res as $val) { if ($val['list_item_id'] == $cell) { $value = $val['item_desc']; } } } if ($excel_outArr['map_type'] == 'items') { $items = $excel_outArr['map_lists']; foreach ($items as $val) { if ($val['key'] == $cell) { $value = $val['desc']; } } } if ($excel_outArr['map_type'] == 'select') { $attrArr = unserialize($columnInfo['column_attrs']); $result = array(); //0为数据库类型 if ($attrArr['type'] == 0) { $result = $this->CM()->query($attrArr['data_sql']); foreach ($result as $singleRow) { if ($singleRow[$attrArr['value_key']] == $cell) { $value = $singleRow[$attrArr['value_desc']]; } } } //1为静态数据类型 if ($attrArr['type'] == 1) { $result = $attrArr['lists']; foreach ($result as $singleRow) { if ($singleRow['value'] == $cell) { $value = $singleRow['desc']; } } } //2为list类型 if ($attrArr['type'] == 2) { $list_id = $attrArr['list_id']; $result = $this->CM('cm_list_item')->where('list_id=' . $list_id)->select(); foreach ($result as $singleRow) { if ($singleRow['list_item_id'] == $cell) { $value = $singleRow['item_desc']; } } } } $objActSheet->setCellValue($index[$key2] . ($recordKey + 2), $value); } } } } //exit; //导出的文件名 $fileName = 'myExcel' . time() . '.xlsx'; $outputFileName = iconv('UTF-8', 'gb2312', $fileName); //直接导出文件 $objWriter->save($outputFileName); vendor('Form.File'); $file = File::getInstance(); //$file::downloads($fileName); }
public function copyTpl($tplName) { Vendor('Form.File'); $file = File::getInstance(); $back = $file::copydir('./Admin/Tpl/DemoTpl', './Admin/Tpl/' . $tplName); $con = file_get_contents('./Admin/Tpl/' . $tplName . '/list.html'); $str = str_replace('__APP__/Demo/Demo_add', '__APP__/' . $tplName . '/' . $tplName . '_add', $con); file_put_contents('./Admin/Tpl/' . $tplName . '/list.html', $str); }