word下载
Posted xin-jun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了word下载相关的知识,希望对你有一定的参考价值。
/** * 批量下载简历 */ public function batch() { $str = $this->_param[‘str‘]; $arr = json_decode($str, 1); $time = date(‘YmdHis‘); $filedir = ROOT_PATH . "public/docx/delivery/"; //删除不是当天创建的文件 $arrfile = $this->getFileName($filedir); foreach ($arrfile as $val) { if (is_dir($filedir . $val)) { $str = substr($val, 0, 8); if (date(‘Ymd‘) > $str) { $this->delSelfDif($filedir . $val . ‘/‘); } } } $fileNameArr = array(); foreach ($arr as $val) { $fileNameArr[] = $this->downLoadWords($val, $time); } $filename = ROOT_PATH . "public/docx/delivery/" . $time . "/" . $time . ".zip"; // 最终生成的文件名(含路径) // 生成文件 $zip = new ipArchive (); // 使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open($filename, IPARCHIVE::CREATE) !== TRUE) { exit(‘无法打开文件,或者文件创建失败‘); } //$fileNameArr 就是一个存储文件路径的数组 比如 array(‘/a/1.jpg,/a/2.jpg....‘); foreach ($fileNameArr as $val) { $zip->addFile($val, preg_replace(‘/^.+[\\\/]/‘, ‘‘, $val)); // 第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下 } $zip->close(); // 关闭 //下面是输出下载; header("Cache-Control: max-age=0"); header("Content-Description: File Transfer"); header(‘Content-disposition: attachment; filename=‘ . basename($filename)); // 文件名 header("Content-Type: application/zip"); // zip格式的 header("Content-Transfer-Encoding: binary"); // 告诉浏览器,这是二进制文件 header(‘Content-Length: ‘ . filesize($filename)); // 告诉浏览器,文件大小 @readfile($filename); //输出文件; } /** * 下载个人简历 * @return boolean */ public function downLoadWords($data, $time) { $jobId = $data[‘jobId‘]; //取该职位信息 $res = $this->job_logic->getOne([‘jobId‘ => $jobId]); //职位类别 1:校园 2:社会 $res[‘jobCate‘] = config(‘status.jobCate‘)[$res[‘jobCate‘]]; //工作类别1全职,2兼职 $res[‘jobType‘] = config(‘status.jobCate‘)[$res[‘jobType‘]]; //薪资 $res[‘salary‘] = config(‘status.salary‘)[$res[‘salary‘]]; //学历 $res[‘educationRqe‘] = config(‘status.education‘)[$res[‘educationRqe‘]]; //工作年限 $res[‘workExpRqe‘] = config(‘status.workYears‘)[$res[‘workExpRqe‘]]; //部门 $res[‘departmentName‘] = $this->department_logic->getOneById([‘id‘ => $res[‘departmentId‘]])[‘departmentName‘]; //岗位 $res[‘postName‘] = $this->post_logic->getOneById([‘id‘ => $res[‘postId‘]])[‘postName‘]; //改职位的申请人数 $res[‘countDelivery‘] = $this->delivery_logic->getCountByCondition([‘jobId‘ => $jobId]); //创建新文档... $phpWord = new PhpWord(); $templateProcessor = new TemplateProcessor(‘./example.docx‘); //职位信息填写替换 $templateProcessor->setValue(‘jobCate‘, $res[‘jobCate‘]); $templateProcessor->setValue(‘jobName‘, $res[‘jobName‘]); $templateProcessor->setValue(‘departmentName‘, $res[‘departmentName‘]); $templateProcessor->setValue(‘salary‘, $res[‘salary‘]); $templateProcessor->setValue(‘educationRqe‘, $res[‘educationRqe‘]); $templateProcessor->setValue(‘workExpRqe‘, $res[‘workExpRqe‘]); $templateProcessor->setValue(‘workPlaceId‘, isset(config(‘place‘)[$res[‘provinceId‘]]) && !empty($res[‘provinceId‘]) ? config(‘place‘)[$res[‘provinceId‘]] : ‘‘ . ‘-‘ . isset(config(‘place‘)[$res[‘cityId‘]]) && !empty($res[‘cityId‘]) ? config(‘place‘)[$res[‘cityId‘]] : ‘‘); $templateProcessor->setValue(‘addTime‘, $res[‘addTime‘]); $userId = $data[‘userId‘]; //获取单个用户信息 $deliveryData = $this->delivery_logic->getOneByCondition([‘userId‘ => $userId]); // print_r($deliveryData);exit; $userData = $this->user_logic->getOneByCondition([‘userId‘ => $userId]); //组合新的数组 $deliveryData[‘user‘] = $userData; //取当前简历的教育经历 $educationData = $this->education_logic->getByCondition([‘userId‘ => $userId]); //取当前简历的工作经历 $workData = $this->work_logic->getByCondition([‘userId‘ => $userId]); //个人基本信息替换 $templateProcessor->setValue(‘name‘, isset($deliveryData[‘user‘][‘name‘]) ? $deliveryData[‘user‘][‘name‘] : ‘‘); $templateProcessor->setValue(‘sex‘, isset($deliveryData[‘user‘][‘sex‘]) && !empty($deliveryData[‘user‘][‘sex‘]) ? config(‘status.sex‘)[$deliveryData[‘user‘][‘sex‘]] : ‘‘); $templateProcessor->setValue(‘phone‘, isset($deliveryData[‘user‘][‘phone‘]) ? $deliveryData[‘user‘][‘phone‘] : ‘‘); $templateProcessor->setValue(‘email‘, isset($deliveryData[‘user‘][‘email‘]) ? $deliveryData[‘user‘][‘email‘] : ‘‘); $templateProcessor->setValue(‘birthDay‘, isset($deliveryData[‘user‘][‘birthDay‘]) ? $deliveryData[‘user‘][‘birthDay‘] : ‘‘); $templateProcessor->setValue(‘place‘, !empty($userData[‘provinceId‘]) && !empty(config(‘place‘)[$userData[‘provinceId‘]]) ? config(‘place‘)[$userData[‘provinceId‘]] : (‘‘ . ‘-‘ . ( !empty($userData[‘cityId‘]) && !empty(config(‘place‘)[$userData[‘cityId‘]]) ? config(‘place‘)[$userData[‘cityId‘]] : ‘‘))); $templateProcessor->setValue(‘sex‘, isset($deliveryData[‘user‘][‘sex‘]) && !empty($deliveryData[‘user‘][‘sex‘]) ? config(‘status.sex‘)[$deliveryData[‘user‘][‘sex‘]] : ‘‘); $templateProcessor->setValue(‘yearSalary‘, isset($userData[‘yearSalary‘]) && !empty($userData[‘yearSalary‘]) ? config(‘status.hopeSalary‘)[$userData[‘yearSalary‘]] : ‘‘); //其他信息 $templateProcessor->setValue(‘extra‘, isset($deliveryData[‘user‘][‘extra‘]) ? $deliveryData[‘user‘][‘extra‘] : ‘‘); //工作经历信息替换 //该表通过克隆行的方式,形成count($deliveryData[‘work‘])行 $templateProcessor->cloneRow(‘company‘, count($workData)); for ($i = 1; $i <= count($workData); $i++) { //每行参数是用value#X(X表示行号,从1开始) $templateProcessor->setValue(‘company#‘ . $i, isset($workData[$i - 1][‘company‘]) && !empty($workData[$i - 1][‘company‘]) ? $workData[$i - 1][‘company‘] : ‘‘); $templateProcessor->setValue(‘startDate#‘ . $i, isset($workData[$i - 1][‘startDate‘]) && !empty($workData[$i - 1][‘startDate‘]) ? $workData[$i - 1][‘startDate‘] : ‘‘); $templateProcessor->setValue(‘endDate#‘ . $i, isset($workData[$i - 1][‘endDate‘]) && !empty($workData[$i - 1][‘endDate‘]) ? $workData[$i - 1][‘endDate‘] : ‘‘); $templateProcessor->setValue(‘position#‘ . $i, isset($workData[$i - 1][‘position‘]) && !empty($workData[$i - 1][‘position‘]) ? $workData[$i - 1][‘position‘] : ‘‘); } $templateProcessor->cloneRow(‘school‘, count($educationData)); for ($i = 1; $i <= count($deliveryData); $i++) { $templateProcessor->setValue(‘school#‘ . $i, isset($educationData[$i - 1][‘school‘]) && !empty($educationData[$i - 1][‘school‘]) ? $educationData[$i - 1][‘school‘] : ‘‘); $templateProcessor->setValue(‘eduStartDate#‘ . $i, isset($educationData[$i - 1][‘startDate‘]) && !empty($educationData[$i - 1][‘startDate‘]) ? $educationData[$i - 1][‘startDate‘] : ‘‘); $templateProcessor->setValue(‘eduEndDate#‘ . $i, isset($educationData[$i - 1][‘endDate‘]) && !empty($educationData[$i - 1][‘endDate‘]) ? $educationData[$i - 1][‘endDate‘] : ‘‘); $templateProcessor->setValue(‘major#‘ . $i, isset($educationData[$i - 1][‘major‘]) && !empty($educationData[$i - 1][‘major‘]) ? $educationData[$i - 1][‘major‘] : ‘‘); $templateProcessor->setValue(‘education#‘ . $i, isset($educationData[$i - 1][‘education‘]) && !empty($educationData[$i - 1][‘education‘]) ? config(‘status.education‘)[$educationData[$i - 1][‘education‘]] : ‘‘); } $dir = ROOT_PATH . ‘public/docx/delivery/‘ . $time . ‘/‘; // 判断存放图片目录是否存在 if (!is_dir($dir)) { if (!mkdir($dir)) { return false; } } $name = !empty($deliveryData[‘user‘][‘name‘]) ? $dir . $deliveryData[‘user‘][‘name‘] . ‘.docx‘ : $dir . ‘未知‘ . ‘.docx‘; // Saving the document $templateProcessor->saveAs($name); return $name; } /** * 下载个人简历(单个的) * @return boolean */ public function downLoadWord() { $jobId = $this->_param[‘jobId‘]; //取该职位信息 $res = $this->job_logic->getOne([‘jobId‘ => $jobId]); if (empty($res)) { return json($this->_format_return_data([], FAILED, ‘参数不对‘)); } //职位类别 1:校园 2:社会 $res[‘jobCate‘] = config(‘status.jobCate‘)[$res[‘jobCate‘]]; //工作类别1全职,2兼职 $res[‘jobType‘] = config(‘status.jobCate‘)[$res[‘jobType‘]]; //薪资 $res[‘salary‘] = config(‘status.salary‘)[$res[‘salary‘]]; //学历 $res[‘educationRqe‘] = config(‘status.education‘)[$res[‘educationRqe‘]]; //工作年限 $res[‘workExpRqe‘] = config(‘status.workYears‘)[$res[‘workExpRqe‘]]; //部门 $res[‘departmentName‘] = $this->department_logic->getOneById([‘id‘ => $res[‘departmentId‘]])[‘departmentName‘]; //岗位 $res[‘postName‘] = $this->post_logic->getOneById([‘id‘ => $res[‘postId‘]])[‘postName‘]; //改职位的申请人数 $res[‘countDelivery‘] = $this->delivery_logic->getCountByCondition([‘jobId‘ => $jobId]); //创建新文档... $phpWord = new PhpWord(); $templateProcessor = new TemplateProcessor(‘./example.docx‘); //职位信息填写替换 $templateProcessor->setValue(‘jobCate‘, $res[‘jobCate‘]); $templateProcessor->setValue(‘jobName‘, $res[‘jobName‘]); $templateProcessor->setValue(‘departmentName‘, $res[‘departmentName‘]); $templateProcessor->setValue(‘salary‘, $res[‘salary‘]); $templateProcessor->setValue(‘educationRqe‘, $res[‘educationRqe‘]); $templateProcessor->setValue(‘workExpRqe‘, $res[‘workExpRqe‘]); $templateProcessor->setValue(‘workPlaceId‘, isset(config(‘place‘)[$res[‘provinceId‘]]) && !empty($res[‘provinceId‘]) ? config(‘place‘)[$res[‘provinceId‘]] : ‘‘ . ‘-‘ . isset(config(‘place‘)[$res[‘cityId‘]]) && !empty($res[‘cityId‘]) ? config(‘place‘)[$res[‘cityId‘]] : ‘‘); $templateProcessor->setValue(‘addTime‘, $res[‘addTime‘]); $userId = $this->_param[‘userId‘]; //获取单个用户信息 $deliveryData = $this->delivery_logic->getOneByCondition([‘userId‘ => $userId]); if (empty($deliveryData)) { return json($this->_format_return_data([], FAILED, ‘参数不对‘)); } $userData = $this->user_logic->getOneByCondition([‘userId‘ => $userId]); //组合新的数组 $deliveryData[‘user‘] = $userData; //取当前简历的教育经历 $educationData = $this->education_logic->getByCondition([‘userId‘ => $userId]); //取当前简历的工作经历 $workData = $this->work_logic->getByCondition([‘userId‘ => $userId]); //个人基本信息替换 $templateProcessor->setValue(‘name‘, isset($deliveryData[‘user‘][‘name‘]) ? $deliveryData[‘user‘][‘name‘] : ‘‘); $templateProcessor->setValue(‘sex‘, isset($deliveryData[‘user‘][‘sex‘]) && !empty($deliveryData[‘user‘][‘sex‘]) ? config(‘status.sex‘)[$deliveryData[‘user‘][‘sex‘]] : ‘‘); $templateProcessor->setValue(‘phone‘, isset($deliveryData[‘user‘][‘phone‘]) ? $deliveryData[‘user‘][‘phone‘] : ‘‘); $templateProcessor->setValue(‘email‘, isset($deliveryData[‘user‘][‘email‘]) ? $deliveryData[‘user‘][‘email‘] : ‘‘); $templateProcessor->setValue(‘birthDay‘, isset($deliveryData[‘user‘][‘birthDay‘]) ? $deliveryData[‘user‘][‘birthDay‘] : ‘‘); $templateProcessor->setValue(‘place‘, isset(config(‘place‘)[$userData[‘provinceId‘]]) && !empty($userData[‘provinceId‘]) ? config(‘place‘)[$userData[‘provinceId‘]] : ‘‘ . ‘-‘ . isset(config(‘place‘)[$userData[‘cityId‘]]) && !empty($userData[‘cityId‘]) ? config(‘place‘)[$userData[‘cityId‘]] : ‘‘); $templateProcessor->setValue(‘yearSalary‘, isset($userData[‘yearSalary‘]) && !empty($userData[‘yearSalary‘]) ? config(‘status.hopeSalary‘)[$userData[‘yearSalary‘]] : ‘‘); //其他信息 $templateProcessor->setValue(‘extra‘, isset($deliveryData[‘user‘][‘extra‘]) ? $deliveryData[‘user‘][‘extra‘] : ‘‘); //工作经历信息替换 //该表通过克隆行的方式,形成count($deliveryData[‘work‘])行 $templateProcessor->cloneRow(‘company‘, count($workData)); for ($i = 1; $i <= count($workData); $i++) { //每行参数是用value#X(X表示行号,从1开始) $templateProcessor->setValue(‘company#‘ . $i, isset($workData[$i - 1][‘company‘]) && !empty($workData[$i - 1][‘company‘]) ? $workData[$i - 1][‘company‘] : ‘‘); $templateProcessor->setValue(‘startDate#‘ . $i, isset($workData[$i - 1][‘startDate‘]) && !empty($workData[$i - 1][‘startDate‘]) ? $workData[$i - 1][‘startDate‘] : ‘‘); $templateProcessor->setValue(‘endDate#‘ . $i, isset($workData[$i - 1][‘endDate‘]) && !empty($workData[$i - 1][‘endDate‘]) ? $workData[$i - 1][‘endDate‘] : ‘‘); $templateProcessor->setValue(‘position#‘ . $i, isset($workData[$i - 1][‘position‘]) && !empty($workData[$i - 1][‘position‘]) ? $workData[$i - 1][‘position‘] : ‘‘); } //教育经历 $templateProcessor->cloneRow(‘school‘, count($educationData)); for ($i = 1; $i <= count($deliveryData); $i++) { $templateProcessor->setValue(‘school#‘ . $i, isset($educationData[$i - 1][‘school‘]) && !empty($educationData[$i - 1][‘school‘]) ? $educationData[$i - 1][‘school‘] : ‘‘); $templateProcessor->setValue(‘eduStartDate#‘ . $i, isset($educationData[$i - 1][‘startDate‘]) && !empty($educationData[$i - 1][‘startDate‘]) ? $educationData[$i - 1][‘startDate‘] : ‘‘); $templateProcessor->setValue(‘eduEndDate#‘ . $i, isset($educationData[$i - 1][‘endDate‘]) && !empty($educationData[$i - 1][‘endDate‘]) ? $educationData[$i - 1][‘endDate‘] : ‘‘); $templateProcessor->setValue(‘major#‘ . $i, isset($educationData[$i - 1][‘major‘]) && !empty($educationData[$i - 1][‘major‘]) ? $educationData[$i - 1][‘major‘] : ‘‘); $templateProcessor->setValue(‘education#‘ . $i, isset($educationData[$i - 1][‘education‘]) && !empty($educationData[$i - 1][‘education‘]) ? config(‘status.education‘)[$educationData[$i - 1][‘education‘]] : ‘‘); } $dir = ROOT_PATH . ‘public/docx/deliveryOne/‘; // 判断存放图片目录是否存在 if (!is_dir($dir)) { if (!mkdir($dir)) { return false; } } $name = $dir . $deliveryData[‘user‘][‘name‘] . ‘.docx‘; $this->deldir(ROOT_PATH . ‘public/docx/deliveryOne‘); // Saving the document $templateProcessor->saveAs($name); return json(self::_format_return_data(‘http://‘ . $_SERVER[‘HTTP_HOST‘] . ‘/docx/deliveryOne/‘ . $deliveryData[‘user‘][‘name‘] . ‘.docx‘)); //操作成功 } /** * 下载登记表 * @return boolean */ public function downLoadInterview() { $jobId = $this->_param[‘jobId‘]; //创建新文档... $phpWord = new PhpWord(); $templateProcessor = new TemplateProcessor(‘./jobHunder.docx‘); //取该职位信息 $res = $this->job_logic->getOne([‘jobId‘ => $jobId]); if (empty($res)) { return json($this->_format_return_data([], FAILED, ‘参数不对‘)); } //职位信息填写替换 $templateProcessor->setValue(‘jobName‘, $res[‘jobName‘]); //取面试申请信息 $userId = $this->_param[‘userId‘]; $interviewData = $this->interview_logic->getOneByCondition([‘userId‘ => $userId, ‘jobId‘ => $jobId]); if (empty($interviewData)) { return json($this->_format_return_data([], FAILED, ‘参数不对‘)); } $templateProcessor->setValue(‘entryTime‘, $interviewData[‘entryTime‘]); $templateProcessor->setValue(‘hopeSalary‘, config(‘status.hopeSalary‘)[$interviewData[‘hopeSalary‘]]); $templateProcessor->setValue(‘presentSalary‘, $interviewData[‘presentSalary‘]); $templateProcessor->setValue(‘name‘, $interviewData[‘name‘]); $templateProcessor->setValue(‘phone‘, $interviewData[‘phone‘]); $templateProcessor->setValue(‘birthday‘, $interviewData[‘birthday‘]); $templateProcessor->setValue(‘education‘, !empty($interviewData[‘education‘])?config(‘status.education‘)[$interviewData[‘education‘]]:‘‘); $templateProcessor->setValue(‘sex‘, !empty($interviewData[‘sex‘])?config(‘status.sex‘)[$interviewData[‘sex‘]]:‘‘); $templateProcessor->setValue(‘marStatus‘, !empty($interviewData[‘marStatus‘])?config(‘status.marStatus‘)[$interviewData[‘marStatus‘]]:‘‘); $templateProcessor->setValue(‘IDcard‘, $interviewData[‘IDcard‘]); $templateProcessor->setValue(‘country‘, $interviewData[‘country‘]); $templateProcessor->setValue(‘email‘, $interviewData[‘email‘]); $templateProcessor->setValue(‘oldAddress‘, $interviewData[‘oldAddress‘]); $templateProcessor->setValue(‘address‘, $interviewData[‘address‘]); $templateProcessor->setValue(‘urgentName‘, $interviewData[‘urgentName‘]); $templateProcessor->setValue(‘urgentReletion‘, $interviewData[‘urgentReletion‘]); $templateProcessor->setValue(‘urgentPhone‘, $interviewData[‘urgentPhone‘]); $templateProcessor->setValue(‘urgentAddress‘, $interviewData[‘urgentAddress‘]); //取当前简历的教育经历 $educationData = $this->education_logic->getByCondition([‘userId‘ => $userId]); if (!empty($educationData)) { //教育信息替换 //该表通过克隆行的方式,形成count($deliveryData[‘work‘])行 $templateProcessor->cloneRow(‘school‘, count($educationData)); for ($i = 1; $i <= count($educationData); $i++) { //每行参数是用value#X(X表示行号,从1开始) $templateProcessor->setValue(‘school#‘ . $i, !empty($educationData[$i - 1][‘school‘]) ? $educationData[$i - 1][‘school‘] : ‘‘); $templateProcessor->setValue(‘startDate#‘ . $i, !empty($educationData[$i - 1][‘startDate‘]) ? $educationData[$i - 1][‘startDate‘] : ‘‘); $templateProcessor->setValue(‘endDate#‘ . $i, !empty($educationData[$i - 1][‘endDate‘]) ? $educationData[$i - 1][‘endDate‘] : ‘‘); $templateProcessor->setValue(‘major#‘ . $i, !empty($educationData[$i - 1][‘major‘]) ? $educationData[$i - 1][‘major‘] : ‘‘); $templateProcessor->setValue(‘education#‘ . $i, !empty($educationData[$i - 1][‘education‘]) ? config(‘status.education‘)[$educationData[$i - 1][‘education‘]] : ‘‘); } } else { $templateProcessor->setValue(‘school‘, ‘‘); $templateProcessor->setValue(‘startDate‘, ‘‘); $templateProcessor->setValue(‘endDate‘, ‘‘); $templateProcessor->setValue(‘major‘, ‘‘); $templateProcessor->setValue(‘education‘, ‘‘); } //取当前简历的工作经历 $workData = $this->work_logic->getByCondition([‘userId‘ => $userId]); if (!empty($workData)) { //工作经历信息替换 //该表通过克隆行的方式,形成count($deliveryData[‘work‘])行 $templateProcessor->cloneRow(‘company‘, count($workData)); for ($i = 1; $i <= count($workData); $i++) { //每行参数是用value#X(X表示行号,从1开始) $templateProcessor->setValue(‘company#‘ . $i, !empty($workData[$i - 1][‘company‘]) ? $workData[$i - 1][‘company‘] : ‘‘); $templateProcessor->setValue(‘startDate#‘ . $i, !empty($workData[$i - 1][‘startDate‘]) ? $workData[$i - 1][‘startDate‘] : ‘‘); $templateProcessor->setValue(‘endDate#‘ . $i, !empty($workData[$i - 1][‘endDate‘]) ? $workData[$i - 1][‘endDate‘] : ‘‘); $templateProcessor->setValue(‘position#‘ . $i, !empty($workData[$i - 1][‘position‘]) ? $workData[$i - 1][‘position‘] : ‘‘); $templateProcessor->setValue(‘resaon#‘ . $i, !empty($workData[$i - 1][‘resaon‘]) ? $workData[$i - 1][‘resaon‘] : ‘‘); $templateProcessor->setValue(‘reterence#‘ . $i, !empty($workData[$i - 1][‘reterence‘]) ? $workData[$i - 1][‘reterence‘] : ‘‘); $templateProcessor->setValue(‘reterPosition#‘ . $i, !empty($workData[$i - 1][‘reterPosition‘]) ? $workData[$i - 1][‘reterPosition‘] : ‘‘); $templateProcessor->setValue(‘reterPhone#‘ . $i, !empty($workData[$i - 1][‘reterPhone‘]) ? $workData[$i - 1][‘reterPhone‘] : ‘‘); } } else { $templateProcessor->setValue(‘company‘, ‘‘); $templateProcessor->setValue(‘startDate‘, ‘‘); $templateProcessor->setValue(‘endDate‘, ‘‘); $templateProcessor->setValue(‘position‘, ‘‘); $templateProcessor->setValue(‘resaon‘, ‘‘); $templateProcessor->setValue(‘reterence‘, ‘‘); $templateProcessor->setValue(‘reterPosition‘, ‘‘); $templateProcessor->setValue(‘reterPhone‘, ‘‘); } if ($interviewData[‘getInfo‘] == 0) $templateProcessor->setValue(‘path‘, ‘□招聘网站 Job Board □猎头 Headhunter(公司名称 Company: ) □内部推荐 Internal Referral(推荐人 Referee: ) □波士顿科学招聘微信公众号 BSC WeChat Account‘); if ($interviewData[‘getInfo‘] == 1) $templateProcessor->setValue(‘path‘, ‘?招聘网站 Job Board □猎头 Headhunter(公司名称 Company: ) □内部推荐 Internal Referral(推荐人 Referee: ) □波士顿科学招聘微信公众号 BSC WeChat Account‘); if ($interviewData[‘getInfo‘] == 2) $templateProcessor->setValue(‘path‘, ‘□招聘网站 Job Board ?猎头 Headhunter(公司名称 Company:‘ . $interviewData[‘getName‘] . ‘) □内部推荐 Internal Referral(推荐人 Referee: ) □波士顿科学招聘微信公众号 BSC WeChat Account‘); if ($interviewData[‘getInfo‘] == 3) $templateProcessor->setValue(‘path‘, ‘□招聘网站 Job Board □猎头 Headhunter(公司名称 Company: ) ?内部推荐 Internal Referral(推荐人 Referee:‘ . $interviewData[‘getName‘] . ‘) □波士顿科学招聘微信公众号 BSC WeChat Account‘); if ($interviewData[‘getInfo‘] == 4) $templateProcessor->setValue(‘path‘, ‘□招聘网站 Job Board □猎头 Headhunter(公司名称 Company: ) □内部推荐 Internal Referral(推荐人 Referee: ) ?波士顿科学招聘微信公众号 BSC WeChat Account‘); if ($interviewData[‘isill‘] == 1) { $templateProcessor->setValue(‘isill‘, ‘□无 No ?是‘); $templateProcessor->setValue(‘illInfo‘, $interviewData[‘illInfo‘]); } else { $templateProcessor->setValue(‘isill‘, ‘?无 No □是‘); $templateProcessor->setValue(‘illInfo‘, ‘‘); } if ($interviewData[‘isPunish‘] == 1) { $templateProcessor->setValue(‘isPunish‘, ‘□无 No ?是‘); $templateProcessor->setValue(‘punishInfo‘, $interviewData[‘punishInfo‘]); } else { $templateProcessor->setValue(‘isPunish‘, ‘?无 No □是‘); $templateProcessor->setValue(‘punishInfo‘, ‘‘); } if ($interviewData[‘isRelative‘] == 1) { $templateProcessor->setValue(‘isRelative‘, ‘□无 No ?是‘); $templateProcessor->setValue(‘relativeName‘, $interviewData[‘relativeName‘]); } else { $templateProcessor->setValue(‘isRelative‘, ‘?无 No □是‘); $templateProcessor->setValue(‘relativeName‘, ‘‘); } if ($interviewData[‘isDepartment‘] == 1) { $templateProcessor->setValue(‘isDepartment‘, ‘□无 No ?是‘); $templateProcessor->setValue(‘departName‘, $interviewData[‘departName‘]); } else { $templateProcessor->setValue(‘isDepartment‘, ‘?无 No □是‘); $templateProcessor->setValue(‘departName‘, ‘‘); } if ($interviewData[‘isMedical‘] == 1) { $templateProcessor->setValue(‘isMedical‘, ‘□无 No ?是‘); $templateProcessor->setValue(‘medicalName‘, $interviewData[‘medicalName‘]); } else { $templateProcessor->setValue(‘isMedical‘, ‘?无 No □是‘); $templateProcessor->setValue(‘medicalName‘, ‘‘); } $dir = ROOT_PATH . ‘public/docx/interview‘; // 判断存放图片目录是否存在 if (!is_dir($dir)) { if (!mkdir($dir)) { return false; } } $name = $dir . ‘/‘ . $interviewData[‘name‘] . ‘.docx‘; $this->deldir(ROOT_PATH . ‘public/docx/interview‘); // Saving the document $templateProcessor->saveAs($name); return json(self::_format_return_data(‘http://‘ . $_SERVER[‘HTTP_HOST‘] . ‘/docx/interview/‘ . $interviewData[‘name‘] . ‘.docx‘)); //操作成功// header(‘Location:‘ . ‘http://‘ . $_SERVER[‘HTTP_HOST‘] . ‘/docx/interview/jobHunder.docx‘); } /** * 删除文件夹下的所有文件 * @param type $dir */ public function deldir($dir) { //删除目录下的文件: $dh = opendir($dir); while ($file = readdir($dh)) { if ($file != "." && $file != "..") { $fullpath = $dir . "/" . $file; if (!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } } closedir($dh); } /** * 获取文件夹中的文件名 * @param type $path * @return type */ public function getFileName($path) { $arr = array(); $handler = opendir($path); //当前目录中的文件夹下的文件夹 while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { $arr[] = $filename; } } closedir($handler); return $arr; } /** * 删除包含自己的文件夹 * @param type $dir * @return boolean */ public function delSelfDif($dir) { //先删除目录下的文件: $dh = opendir($dir); while ($file = readdir($dh)) { if ($file != "." && $file != "..") { $fullpath = $dir . "/" . $file; if (!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } } closedir($dh); //删除当前文件夹: if (rmdir($dir)) { return true; } else { return false; } }
以上是关于word下载的主要内容,如果未能解决你的问题,请参考以下文章