本文整理匯總了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');
}