public function simgupload()
 {
     //初始化上传类
     $Upload = new Upload();
     $Upload->maxSize = $this->_upfilesize['image']['size'];
     $Upload->exts = $this->_upfilesize['image']['exts'];
     $Upload->rootPath = UPLOAD_PATH;
     $Upload->savePath = 'scrollimage/';
     $Upload->saveName = array('uniqid', '');
     $Upload->autoSub = true;
     $Upload->subName = array('date', 'Ym');
     //上传
     $error = null;
     $msg = '上传成功!';
     $data = array();
     $info = $Upload->upload();
     if (!$info) {
         $error = 1;
         $msg = $Upload->getError();
     } else {
         $fileinfo = array_shift($info);
         $data = array('filepath' => '/' . UPLOAD_PT . $fileinfo['savepath'], 'filename' => $fileinfo['savename']);
     }
     $this->ajaxReturn($error, $msg, $data);
 }
 public function workfileupload()
 {
     //初始化上传类
     $Upload = new Upload();
     $Upload->maxSize = 2097152;
     //2M
     $Upload->exts = array('doc', 'docx');
     $Upload->rootPath = UPLOAD_PATH;
     $Upload->savePath = 'file/workfile/';
     $Upload->saveName = array('uniqid', array('', true));
     $Upload->autoSub = true;
     $Upload->subName = array('date', 'Ym');
     //上传
     $error = null;
     $msg = '报告提交成功!';
     $data = array();
     $info = $Upload->upload();
     if (!$info) {
         $error = 1;
         $msg = $Upload->getError();
     } else {
         $workid = mRequest('workid');
         if (!$workid) {
             $this->ajaxReturn(1, '请选择作业!');
         }
         $fileinfo = array_shift($info);
         $data = array('userid' => $this->userinfo['userid'], 'workid' => $workid, 'savepath' => '/' . UPLOAD_PT . $fileinfo['savepath'], 'savename' => $fileinfo['savename'], 'filename' => $fileinfo['name'], 'filesize' => $fileinfo['size'], 'ext' => $fileinfo['ext'], 'createtime' => TIMESTAMP);
         //开始事务
         M('user_work')->startTrans();
         $userworkid = M('user_work')->add(array('userid' => $this->userinfo['userid'], 'workid' => $workid, 'status' => 1, 'createtime' => TIMESTAMP));
         $fileid = M('user_work_file')->add($data);
         if ($userworkid && $fileid) {
             M('user_work')->commit();
         } else {
             M('user_work')->rollback();
             $error = 1;
             $msg = '报告提交失败!请重新提交!';
         }
     }
     $this->ajaxReturn($error, $msg, $data);
 }
 public function excelexam()
 {
     //初始化上传类
     $Upload = new Upload();
     $Upload->maxSize = $this->_upfilesize['attach']['size'];
     $Upload->exts = $this->_upfilesize['attach']['exts'];
     $Upload->rootPath = UPLOAD_PATH;
     $Upload->savePath = 'file/excelexam/';
     $Upload->saveName = array('uniqid', array('', true));
     $Upload->autoSub = true;
     $Upload->subName = array('date', 'Ym');
     //上传
     $error = null;
     $msg = '上传成功!';
     $data = array();
     $info = $Upload->upload();
     if (!$info) {
         $error = 1;
         $msg = $Upload->getError();
     } else {
         $fileinfo = array_shift($info);
         $excelexamfile = UPLOAD_PATH . $fileinfo['savepath'] . $fileinfo['savename'];
         //试题信息html
         $examhtml = '';
         //读取excel试题文件
         require_once VENDOR_PATH . 'PHPExcel/PHPExcel/IOFactory.php';
         $objPHPExcel = \PHPExcel_IOFactory::load($excelexamfile);
         $cSheet = $objPHPExcel->getSheet(0);
         $maxRow = $cSheet->getHighestRow();
         // 取得总行数
         $maxColumn = $cSheet->getHighestColumn();
         // 取得总列数
         $row = 2;
         $col = 'A';
         for ($row = 2; $row <= $maxRow; $row++) {
             $examitem = array();
             for ($col = 'A'; $col <= $maxColumn; $col++) {
                 $val = $cSheet->getCellByColumnAndRow(ord($col) - 65, $row)->getValue();
                 /**ord()将字符转为十进制数*/
                 //题目
                 if ($col == 'A') {
                     $examitem['title'] = $val;
                 }
                 //答案
                 if ($col == 'B') {
                     $examitem['answer'] = $val;
                     $examitem['type'] = strlen($val) > 1 ? 2 : 1;
                 }
                 //选项A
                 if ($col == 'C') {
                     $c = 1;
                     $examitem['options'][] = array('name' => 'A', 'title' => str_replace('A.', '', $val, $c));
                 }
                 //选项B
                 if ($col == 'D') {
                     $c = 1;
                     $examitem['options'][] = array('name' => 'B', 'title' => str_replace('B.', '', $val, $c));
                 }
                 //选项C
                 if ($col == 'E') {
                     $c = 1;
                     $examitem['options'][] = array('name' => 'C', 'title' => str_replace('C.', '', $val, $c));
                 }
                 //选项D
                 if ($col == 'F') {
                     $c = 1;
                     $examitem['options'][] = array('name' => 'D', 'title' => str_replace('D.', '', $val, $c));
                 }
                 //分数
                 // if ($col == 'G') {
                 //     $examitem['score'] = $val;
                 // }
             }
             $examitem['createtime'] = TIMESTAMP;
             $examitem['updatetime'] = TIMESTAMP;
             $examid = D('Testing')->examsave($examitem);
             if ($examid) {
                 $examitem['examid'] = $examid;
                 $this->assign('examinfo', $examitem);
                 $examhtml .= $this->fetch('Testing/examitem');
             }
         }
         $data = array('examhtml' => $examhtml);
     }
     $this->ajaxReturn($error, $msg, $data);
 }
 public function reviewfileupload()
 {
     //初始化上传类
     $Upload = new Upload();
     $Upload->maxSize = $this->_upfilesize['attach']['size'];
     $Upload->exts = $this->_upfilesize['attach']['exts'];
     $Upload->rootPath = UPLOAD_PATH;
     $Upload->savePath = 'course/review/';
     $Upload->saveName = array('uniqid', array('', true));
     $Upload->autoSub = true;
     $Upload->subName = array('date', 'Ym');
     //上传
     $error = null;
     $msg = '上传成功!';
     $data = array();
     $info = $Upload->upload();
     if (!$info) {
         $error = 1;
         $msg = $Upload->getError();
     } else {
         $fileinfo = array_shift($info);
         $savepath = '/' . UPLOAD_PT . $fileinfo['savepath'];
         $savename = $fileinfo['savename'];
         $filename = $fileinfo['name'];
         $filesize = $fileinfo['size'];
         $ext = $fileinfo['ext'];
         //复习资料信息写入数据库
         $reviewdata = array('courseid' => 0, 'savepath' => $savepath, 'savename' => $savename, 'filename' => $filename, 'filesize' => $filesize, 'ext' => $ext, 'dloadnum' => 0, 'createtime' => TIMESTAMP, 'updatetime' => TIMESTAMP);
         $reviewid = D('Course')->saveReview($reviewdata);
         $data = array('filepath' => '', 'filename' => $reviewid);
     }
     $this->ajaxReturn($error, $msg, $data);
 }