本文整理汇总了PHP中Func::dumpFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Func::dumpFile方法的具体用法?PHP Func::dumpFile怎么用?PHP Func::dumpFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::dumpFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: backup
/**
* 数据库备份
*/
public function backup()
{
set_time_limit(0);
$data = array();
if ($_POST) {
$backup_dir = BASEPATH . '../cache/backup/';
if (!is_dir($backup_dir)) {
mkdir($backup_dir, '0777', true);
}
include dirname(__FILE__) . '/../../config/config.db.php';
$cfg = $db[$db['active_group']];
$is_export_student = intval($this->input->post('is_export_student'));
$sql_file = DbmanageModel::backupTables($cfg['database'], $backup_dir, array('*'), $is_export_student);
if (file_exists($backup_dir . $sql_file)) {
require_once APPPATH . 'libraries/Pclzip.php';
$save_file = $backup_dir . "/zmte_database.zip";
if (is_file($save_file)) {
@unlink($save_file);
}
$archive = new PclZip($save_file);
//将文件进行压缩
$archive->create($backup_dir . $sql_file, PCLZIP_OPT_REMOVE_ALL_PATH);
@unlink($backup_dir . $sql_file);
Func::dumpFile('application/zip', $save_file, 'zmte_database_' . date('YmdHis') . '.zip');
@unlink($save_file);
redirect('/admin/dbmanage/backup');
} else {
message('数据库备份失败,请稍后重试!');
}
} else {
$this->load->view('dbmanage/backup', $data);
}
}
示例2: import_titc_excel
/**
* 导入机构和校区记录(从excel文件中),
* 注意: 目前$ti_id参数未启用
*
* @param int $ti_id = NULL 默认将校区全导入到该机构ID下
*/
public function import_titc_excel($ti_id = NULL)
{
if ($_GET['dl'] == '1') {
Func::dumpFile('application/vnd.ms-excel', 'file/import_training_campus_template.xls', '培训机构及校区导入模板.xls');
exit;
}
$data = array();
while (isset($_FILES['file'])) {
$param = $_POST;
$err_map = array(UPLOAD_ERR_OK => '没有错误发生,文件上传成功', UPLOAD_ERR_INI_SIZE => '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值', UPLOAD_ERR_FORM_SIZE => '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值', UPLOAD_ERR_PARTIAL => '文件只有部分被上传', UPLOAD_ERR_NO_FILE => '没有文件被上传', UPLOAD_ERR_NO_TMP_DIR => '找不到临时文件夹', UPLOAD_ERR_CANT_WRITE => '文件写入失败');
if ($_FILES['file']['error'] !== 0) {
$data['error'] = $err_map[$_FILES['file']['error']];
break;
}
if (strpos($_FILES['file']['type'], 'excel') === false) {
$mime = mime_content_type($_FILES['file']['tmp_name']);
if (!in_array($mime, array('application/vnd.ms-excel', 'application/vnd.ms-office', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))) {
$data['error'] = "您上传的不是Excel文件({$mime})";
break;
}
}
// 开始处理excel
$excel = PHPExcel_IOFactory::load($_FILES['file']['tmp_name']);
$sheet = $excel->getSheet(0);
$row_num = $sheet->getHighestRow();
$col_num = $sheet->getHighestColumn();
$title = array('机构名称', '机构类型', '机构省份', '机构城市', '机构区县', '机构地址', '优先级', '学员人数/年', '机构网址', '校区名称', '校区省份', '校区城市', '校区区县', '校区地址', '联系人', '联系电话');
$col_num = base_convert($col_num, 36, 10);
if ($col_num < count($title)) {
$data['error'] = 'Excel列数验证未通过';
break;
}
$col_num = count($title);
$col_char = array();
for ($j = 0; $j < $col_num; $j++) {
$col_char[$j] = strtoupper(base_convert(10 + $j, 10, 36));
if ($title[$j] !== trim($sheet->getCell($col_char[$j] . '1')->getValue())) {
$data['error'] = $col_char[$j] . '列标题不符';
break;
}
}
if (isset($data['error'])) {
break;
}
$rows = array();
for ($i = 2; $i <= $row_num; $i++) {
$rows[$i - 2] = array();
for ($j = 0; $j < $col_num; $j++) {
$rows[$i - 2][$j] = trim($sheet->getCell($col_char[$j] . $i)->getValue());
}
if ($rows[$i - 2][0] == '') {
unset($rows[$i - 2]);
break;
}
}
unset($sheet);
unset($excel);
if (empty($rows)) {
$data['error'] = 'Excel文件工作表中没有任何要导入的记录';
break;
}
$tit_map = array_flip(array_map("trim", TrainingInstitutionModel::trainingInstitutionTypePairs()));
$tipt_map = array_flip(array_map("trim", TrainingInstitutionModel::trainingInstitutionPriTypePairs()));
$sql = <<<EOT
SELECT * FROM rd_region WHERE region_id > 1 ORDER BY region_type
EOT;
$region_list = Fn::db()->fetchAll($sql);
// 以region_id为键以行记录为值,同时加个children,以保存直接子项
$region_map = array();
// 以名字加'_'连接起来为键,以region_id为值
$regionname_map = array();
foreach ($region_list as $v) {
$region_map[$v['region_id']] = $v;
$region_map[$v['region_id']]['children'] = array();
if ($v['region_type'] == 1) {
$regionname_map[trim($v['region_name'])] = $v['region_id'];
} else {
if ($v['region_type'] == 2) {
$region_map[$v['parent_id']]['children'][] = $v['region_id'];
$regionname_map[trim($region_map[$v['parent_id']]['region_name']) . '_' . trim($v['region_name'])] = $v['region_id'];
} else {
if ($v['region_type'] == 3) {
$region_map[$v['parent_id']]['children'][] = $v['region_id'];
$regionname_map[trim($region_map[$region_map[$v['parent_id']]['parent_id']]['region_name']) . '_' . trim($region_map[$v['parent_id']]['region_name']) . '_' . trim($v['region_name'])] = $v['region_id'];
}
}
}
}
unset($region_list);
$row_num = count($rows);
$ti_arr = array();
//ti_arr[ti_name] => ti_list[i]
$tc_arr = array();
//tc_arr[ti_name][tc_name] => tc_list[i]
//.........这里部分代码省略.........
示例3: down_teacher_report
/**
* 下载班级报告
*/
public function down_teacher_report($rule_id = 0)
{
$rule_id = intval($rule_id);
$rule_id && ($rule = EvaluateRuleModel::get_evaluate_rule($rule_id));
if (empty($rule)) {
message('不存在该评估规则');
}
$save_file = realpath(dirname(APPPATH)) . "/cache/down_teacher_report/" . $rule_id . '.zip';
if (!file_exists($save_file)) {
$teacher_list = TeacherStudentModel::examTeacherList($rule['exam_pid']);
if (!$teacher_list) {
message('当前评估规则没有关联教师,无法下载教师报告!');
}
$dir_name = realpath(dirname(APPPATH)) . "/cache/down_teacher_report/" . $rule_id;
if (!is_dir($dir_name)) {
@mkdir($dir_name, 0777, true);
}
$pdf_dir = C('html2pdf_path') . '/zeming/report/';
$pdf_ready = false;
foreach ($teacher_list as $ct_id => $item) {
$dir = $pdf_dir . "{$rule_id}/teacher_{$ct_id}";
if (!is_dir($dir)) {
continue;
}
$pdf_ready = true;
$teacher_name = $item['ct_name'];
$f = @dir($dir);
if ($f) {
while (false !== ($entry = $f->read())) {
if ($entry != '.' && $entry != '..') {
@copy($dir . '/' . $entry, $dir_name . '/' . $teacher_name . '_' . $entry);
}
}
}
}
if ($pdf_ready) {
require_once APPPATH . 'libraries/Pclzip.php';
$archive = new PclZip($save_file);
//将文件进行压缩
$archive->create($dir_name, PCLZIP_OPT_REMOVE_PATH, realpath(dirname(APPPATH)) . "/cache/down_teacher_report");
$this->rm_dir($dir_name);
} else {
message('教师报告PDF文件还未生成,无法下载!');
}
}
if (file_exists($save_file)) {
$exam_name = ExamModel::get_exam($rule['exam_pid'], 'exam_name');
$subject_name = '';
if ($rule['subject_id'] > 0) {
$subject_name = $this->_subject_name($rule['exam_pid'], $rule['subject_id']);
}
$filename = $exam_name . $subject_name . '教师报告';
Func::dumpFile('application/zip', $save_file, $filename . '.zip');
}
}
示例4: import
/**
* 导入
*/
public function import($exam_pid = 0)
{
if ($_GET['dl'] == '1') {
Func::dumpFile('application/vnd.ms-excel', 'file/import_teacher_stundent_template.xlsx', '师生关联模板.xlsx');
exit;
}
if (!$exam_pid) {
message('参数错误');
}
$data = array();
while (isset($_FILES['file'])) {
$param = $_POST;
$col_char = array();
$rows = Excel::readSimpleUploadFile2($_FILES['file']);
if (!is_array($rows)) {
$data['error'] = $rows;
break;
}
$subject_map = array_flip(C('subject'));
$db = Fn::db();
$exam_ticket_maprule = ExamModel::get_exam($exam_pid, 'exam_ticket_maprule');
$sql = "SELECT subject_id, exam_id FROM rd_exam\n WHERE exam_pid = {$exam_pid}";
$subject_exam = $db->fetchPairs($sql);
if (!is_array($subject_exam)) {
$data['error'] = '考试期次没有考试学科';
break;
}
$exam_subjectid = array_keys($subject_exam);
$list = array();
$subject_key = array();
foreach ($rows as $k => $row) {
if ($k == 0) {
for ($i = 2; $i <= count($row); $i++) {
$subject_id = $subject_map[str_replace("'", "", trim($row[$i]))];
if ($subject_id && in_array($subject_id, $exam_subjectid)) {
$subject_key[$i] = $subject_id;
}
}
} else {
$student = array();
for ($i = 1; $i <= count($row); $i++) {
if ($i == 1) {
$exam_ticket = trim($row[$i]);
if (!$exam_ticket) {
break;
}
$exam_ticket = exam_ticket_maprule_encode($exam_ticket, $exam_ticket_maprule);
$sql = "SELECT uid, school_id FROM rd_student\n WHERE exam_ticket = '{$exam_ticket}'";
$student = $db->fetchRow($sql);
if (!$student) {
break;
}
$list[$student['uid']]['uid'] = $student['uid'];
} else {
$ct_name = str_replace("'", "", trim($row[$i]));
if (!$ct_name) {
continue;
}
$sql = "SELECT ct_id FROM t_cteacher \n LEFT JOIN t_cteacher_school ON scht_ctid = ct_id\n WHERE scht_schid = {$student['school_id']} \n AND ct_name = '{$ct_name}'";
$ct_id = $db->fetchOne($sql);
if (!$ct_id) {
continue;
}
$list[$student['uid']]['teacher'][$subject_key[$i]] = $ct_id;
}
}
}
}
try {
if (!$db->beginTransaction()) {
throw new Exception('开始导入事务处理失败');
}
$insert = 0;
// 导入教师
foreach ($list as $uid => $row) {
foreach ($row['teacher'] as $subject_id => $ct_id) {
$bind = array('tstu_ctid' => $ct_id, 'tstu_stuid' => $uid, 'tstu_exampid' => $exam_pid, 'tstu_examid' => $subject_exam[$subject_id], 'tstu_subjectid' => $subject_id);
TeacherStudentModel::addTeacherStudent($bind);
$insert++;
}
}
if ($db->commit()) {
$data['success'] = <<<EOT
导入Excel文件({$_FILES['file']['name']})成功,共插入{$insert}条师生记录
EOT;
admin_log('import', 'teacher_student', $data['success']);
} else {
$err = $db->errorInfo()[2];
$db->rollBack();
throw new Exception($err);
}
} catch (Exception $e) {
$data['error'] = $e->getMessage();
}
break;
}
$data['exam_pid'] = $exam_pid;
//.........这里部分代码省略.........
示例5: import_cors_excel
/**
* 导入课程记录(从excel文件中),
* 注意: 目前$cors_id参数未启用
*
* @param int $cors_id = NULL 默认将课程全导入到该课程ID下
*/
public function import_cors_excel($cors_id = NULL)
{
if ($_GET['dl'] == '1') {
Func::dumpFile('application/vnd.ms-excel', 'file/import_course_template.xls', '培训课程导入模板.xls');
exit;
}
$data = array();
while (isset($_FILES['file'])) {
$param = $_POST;
$err_map = array(UPLOAD_ERR_OK => '没有错误发生,文件上传成功', UPLOAD_ERR_INI_SIZE => '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值', UPLOAD_ERR_FORM_SIZE => '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值', UPLOAD_ERR_PARTIAL => '文件只有部分被上传', UPLOAD_ERR_NO_FILE => '没有文件被上传', UPLOAD_ERR_NO_TMP_DIR => '找不到临时文件夹', UPLOAD_ERR_CANT_WRITE => '文件写入失败');
if ($_FILES['file']['error'] !== 0) {
$data['error'] = $err_map[$_FILES['file']['error']];
break;
}
if (strpos($_FILES['file']['type'], 'excel') === false) {
$mime = mime_content_type($_FILES['file']['tmp_name']);
if (!in_array($mime, array('application/vnd.ms-excel', 'application/vnd.ms-office', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))) {
$data['error'] = "您上传的不是Excel文件({$mime})";
break;
}
}
// 开始处理excel
$excel = PHPExcel_IOFactory::load($_FILES['file']['tmp_name']);
$sheet = $excel->getSheet(0);
$row_num = $sheet->getHighestRow();
$col_num = $sheet->getHighestColumn();
$title = array('课程名称', '来源机构', '授课模式', '年级', '学科', '类型', '授课教师', '教师来源', '课程时间', '课程周期', '上课校区', '上课省份', '上课城市', '上课区县', '上课地址', '收费', '上课课时', '联系人', '联系电话', '课程简介', '网址');
$col_num = base_convert($col_num, 36, 10);
if ($col_num < count($title)) {
$data['error'] = 'Excel列数验证未通过';
break;
}
$col_num = count($title);
$col_char = array();
for ($j = 0; $j < $col_num; $j++) {
$col_char[$j] = strtoupper(base_convert(10 + $j, 10, 36));
if ($title[$j] !== trim($sheet->getCell($col_char[$j] . '1')->getValue())) {
$data['error'] = $col_char[$j] . '列标题不符';
break;
}
}
if (isset($data['error'])) {
break;
}
$rows = array();
for ($i = 2; $i <= $row_num; $i++) {
$rows[$i - 2] = array();
for ($j = 0; $j < $col_num; $j++) {
$rows[$i - 2][$j] = trim($sheet->getCell($col_char[$j] . $i)->getValue());
}
if ($rows[$i - 2][0] == '') {
unset($rows[$i - 2]);
break;
}
}
unset($sheet);
unset($excel);
if (empty($rows)) {
$data['error'] = 'Excel文件工作表中没有任何要导入的记录';
break;
}
$cm_map = array_flip(array_map("trim", CourseModel::courseModePairs()));
$grade_map = array_flip(C('grades'));
$subject_map = array_flip(C('subject'));
$ctf_map = array_flip(array_map("trim", CourseModel::courseTeachfromPairs()));
$sql = <<<EOT
SELECT class_id, class_name FROM rd_question_class
EOT;
$class_map = Fn::db()->fetchPairs($sql);
if (!is_array($class_map)) {
$class_map = array();
} else {
$class_map = array_flip(array_map("trim", $class_map));
}
$sql = <<<EOT
SELECT * FROM rd_region WHERE region_id > 1 ORDER BY region_type
EOT;
$region_list = Fn::db()->fetchAll($sql);
// 以region_id为键以行记录为值,同时加个children,以保存直接子项
$region_map = array();
// 以名字加'_'连接起来为键,以region_id为值
$regionname_map = array();
foreach ($region_list as $v) {
$region_map[$v['region_id']] = $v;
$region_map[$v['region_id']]['children'] = array();
if ($v['region_type'] == 1) {
$regionname_map[trim($v['region_name'])] = $v['region_id'];
} else {
if ($v['region_type'] == 2) {
$region_map[$v['parent_id']]['children'][] = $v['region_id'];
$regionname_map[trim($region_map[$v['parent_id']]['region_name']) . '_' . trim($v['region_name'])] = $v['region_id'];
} else {
if ($v['region_type'] == 3) {
$region_map[$v['parent_id']]['children'][] = $v['region_id'];
//.........这里部分代码省略.........
示例6: importteacher
/**
* 导入教师记录(从excel文件中),
*/
public function importteacher($sch_id = 0)
{
if ($_GET['dl'] == '1') {
Func::dumpFile('application/vnd.ms-excel', 'file/import_school_teacher_template.xlsx', '教师导入模板.xlsx');
exit;
}
if (!$sch_id || !SchoolModel::schoolInfo($sch_id)) {
message('学校不存在,无法导入教师!');
}
$data = array();
$data['sch_id'] = $sch_id;
while (isset($_FILES['file'])) {
$param = $_POST;
$title = array('姓名', '年级', '学科', '简介');
$col_char = array();
$rows = Excel::readSimpleUploadFile($_FILES['file'], $title, $col_char);
if (!is_array($rows)) {
$data['error'] = $rows;
break;
}
$grade_map = array_flip(C('grades'));
$subject_map = array_flip(C('subject'));
$ct_list = array();
foreach ($rows as $k => $row) {
//////////////////////////////
// 姓名0 年级1 学科2 简介3
//////////////////////////////
// 姓名
if ($row[0] == '') {
$data['error'] == $col_char[0] . ($k + 2) . ' - "姓名"不可为空';
break;
}
if (mb_strlen($row[0], 'UTF-8') > 30) {
$data['error'] = $col_char[0] . ($k + 2) . ' - "姓名"内容太长了,不可超过30个字符';
break;
}
// 年级
if ($row[1] == '') {
$data['error'] = $col_char[1] . ($k + 2) . ' - "年级"不能为空';
break;
}
$row[1] = str_replace(array(',', ' ', ' ', '、', "\r\n", "\r", "\n"), ',', $row[1]);
$row['ctg_gradeid'] = array();
$arr = explode(',', $row[1]);
foreach ($arr as $v) {
$v = trim($v);
if ($v == '') {
continue;
}
if (isset($grade_map[$v])) {
$row['ctg_gradeid'][] = $grade_map[$v];
} else {
$data['error'] = $col_char[1] . ($k + 2) . ' - "年级"里有不正确的选项';
break;
}
}
if (isset($data['error'])) {
break;
}
if (empty($row['ctg_gradeid'])) {
$data['error'] = $col_char[1] . ($k + 2) . ' - "年级"不能为空';
break;
}
$row['ctg_gradeid'] = array_unique($row['ctg_gradeid']);
// 学科
if ($row[2] == '') {
$data['error'] = $col_char[2] . ($k + 2) . ' - "学科"不能为空';
break;
}
$row[2] = str_replace(array(',', ' ', ' ', '、', "\r\n", "\r", "\n"), ',', $row[2]);
$row['cts_subjectid'] = array();
$arr = explode(',', $row[2]);
foreach ($arr as $v) {
$v = trim($v);
if ($v == '') {
continue;
}
if (isset($subject_map[$v])) {
$row['cts_subjectid'][] = $subject_map[$v];
} else {
$data['error'] = $col_char[2] . ($k + 2) . ' - "学科"里有不正确的选项空';
break;
}
}
if (isset($data['error'])) {
break;
}
if (empty($row['cts_subjectid'])) {
$data['error'] = $col_char[2] . ($k + 2) . ' - "学科"不能为空';
break;
}
$row['cts_subjectid'] = array_unique($row['cts_subjectid']);
// 简介
if ($row[3] == '') {
$row[3] = NULL;
}
$ct_list[] = array('index' => $k + 2, 'ct_name' => $row[0], 'ct_memo' => $row[3], 'ctg_gradeid' => $row['ctg_gradeid'], 'cts_subjectid' => $row['cts_subjectid']);
//.........这里部分代码省略.........
示例7: import
/**
* @description 批量导入管理员
* @author
* @final
*/
public function import()
{
if (!$this->check_power('import_cpuser')) {
return;
}
if ($_GET['dl'] == '1') {
Func::dumpFile('application/vnd.ms-excel', 'file/import_adminuser_template.xlsx', '后台管理员导入模板.xlsx');
exit;
}
$this->load->view('cpuser/import');
}