本文整理汇总了PHP中FileUtil::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::getInstance方法的具体用法?PHP FileUtil::getInstance怎么用?PHP FileUtil::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: basicAction
/**
* 合作机构基本信息
*/
public function basicAction($uni_id)
{
//判断是否是ajax
if ($this->request->isAjax()) {
$validate = new \Validate();
$data['union_logo'] = $validate->getPost('union_logo');
//机构logo
$data['union_name'] = $validate->getPost('union_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu'));
//机构名称
//验证参数
if ($validate->getMessage()) {
$this->end(400);
}
//生成机构logo,缩略图
if ($data['union_logo']) {
$data['union_logo'] = \Func::touchImg($data['union_logo'], 'union_logo');
//监测图片是否生成成功
if (!$data['union_logo']) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $data['union_logo']);
$this->end(400);
}
}
$this->end((new \Union())->updUnionBasic($this->session->get('id'), $uni_id, $data));
}
//机构id
$uni_id = (int) $uni_id;
//获取基本数据
$basic = (new \Union())->getUnionBasic($uni_id);
//加载js
$this->assets->addJs('backend/mt-js/union.js');
$this->view->setVars(['uni_id' => $uni_id, 'basic' => $basic]);
}
示例2: newAction
/**
* 新增校友
*/
public function newAction($col_id)
{
//判断是否ajax
if ($this->request->isAjax()) {
$validate = new \Validate();
$data['col_id'] = $validate->getPost('col_id', \Validate::int());
//学校id
$data['alu_head'] = $validate->getPost('alu_head', \Validate::base64());
//校友头像
$data['alu_name'] = $validate->getPost('alu_name', \Validate::length(15, 2));
//校友名称
$data['alu_desc'] = $validate->getPost('alu_desc', \Validate::length(255, 2));
//校友简介
$data['alu_src'] = $validate->getPost('alu_src', \Validate::length(255, 2));
//资料来源
//验证参数
if ($validate->getMessage()) {
$this->end(400);
}
//生成校友头像
$data['alu_head'] = \Func::touchImg($data['alu_head'], 'alu_head');
//监测图片是否生成成功
if (!$data['alu_head']) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $data['alu_head']);
$this->end(400);
}
//新增动态
$this->end((new \CollegeAlumnus())->addAlumnus($this->session->get('id'), $data));
}
$this->view->setVars(['col_id' => $col_id]);
}
示例3: newAction
/**
* 新增属性
*/
public function newAction()
{
//检查是否是ajax请求
if ($this->request->isAjax()) {
$validate = new \Validate();
$data['att_img'] = $validate->getPost('att_img', \Validate::base64());
//属性图
$data['att_name'] = $validate->getPost('att_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu'));
//属性名称
$data['att_sort'] = $validate->getPost('att_sort', \Validate::int());
//排序
//验证数据
if ($validate->getMessage()) {
$this->end(400);
}
//生成学校logo,缩略图
$data['att_img'] = \Func::touchImg($data['att_img'], 'att_img');
//将生成的图片地址存入img,用户失败时删除
$img = [UPLOAD_PATH . $data['att_img'], UPLOAD_PATH . $data['att_img']];
//监测图片是否全部生成成功
if (!$data['att_img']) {
\FileUtil::getInstance()->unlink($img);
}
//新增高校
$result = (new \Attribute())->addAttribute($this->session->get('id'), $data);
if ($result != 200) {
\FileUtil::getInstance()->unlink($img);
}
$this->end($result);
}
//加载所需js
$this->assets->addJs('backend/mt-js/attribute-new.js');
}
示例4: registerAction
/**
* 注册接口
*/
public function registerAction()
{
$vars = ['mem_phone', 'pho_code', 'mem_account', 'mem_pwd', 'mem_head', 'login_system', 'login_number', 'mem_client_id', 'sign'];
//获取数据
list($mem_phone, $pho_code, $mem_account, $mem_pwd, $mem_head, $login_system, $login_number, $mem_client_id, $sign) = \Verify::getPost($vars);
//验证参数
if (\Verify::getMessage()) {
$this->throwMessage(PARAMETER_FAIL, \Verify::getMessage());
}
//生产图片
$mem_head = \Func::touchImg($mem_head, 'head');
if (!$mem_head) {
$this->throwMessage(ILLEGAL_IMAGE);
}
//验证签名
if (!$this->verifyLoginSign($mem_account, $mem_pwd, $sign)) {
$this->throwMessage(ILLEGAL_SIGN);
}
//注册,并登陆
$member = (new \Member())->register($mem_phone, $pho_code, $mem_account, $mem_pwd, $mem_head, $login_system, $login_number, $mem_client_id);
if (!is_array($member)) {
\FileUtil::getInstance()->unlink(IMG_PATH . $mem_head);
$this->throwMessage($member);
}
$this->throwMessage(OK, $member);
}
示例5: touchImg
/**
* 生成图片
* @param string $base64_source base64编码
* @param string $path_name 分目录
* @param boolean $delete 图片生成错误时,是否删除已生成图片
* @return false|string 成功返回图片路径,失败返回false
*/
public static function touchImg($base64_source, $path_name, $delete = true)
{
//判断图片base64格式,并截取扩展名
$pattern = '/^data:image\\/(?<ext>jpeg|png|gif|jpg);base64,(?<source>\\S+)/';
if (!preg_match($pattern, $base64_source, $match) || !base64_decode($match['source'])) {
return false;
}
//扩展名
if ($match['ext'] != 'png' && $match['ext'] != 'gif' && $match['ext'] != 'jpg' || $match['ext'] == 'jpeg') {
$match['ext'] = 'jpg';
}
//图片名称
$img_name = md5(microtime(true) . mt_rand(1000, 9999)) . '.' . $match['ext'];
//获取图片的服务器地址,以及存入数据库地址
$data_path = '/images/' . $path_name . '/' . date('Ym/d', time()) . '/';
$host_path = UPLOAD_PATH . $data_path;
//创建目录
if (!FileUtil::getInstance()->mkdir($host_path)) {
die(json_encode([['error' => 'No file permissions']]));
}
//生成图片
$host_img = $host_path . $img_name;
file_put_contents($host_img, base64_decode($match['source']));
//判断图片是否损坏
if (!getimagesize($host_img) && $delete) {
//删除算坏图片
unlink($host_img);
return false;
}
return $data_path . $img_name;
}
示例6: addAction
/**
* 回答接口
*/
public function addAction()
{
//取值,参数验证,签名验证
$vars = ['mem_id', 'mem_mark', 'empty_ans_id', 'mem_relation_id', 'que_id', 'ans_content', 'is_img', 'sign'];
$this->beforeGetVarExecVerify($vars, 'post');
//判断是否是图片
if ($this->data['is_img'] == 1) {
$this->data['ans_content'] = \Func::touchImg($this->data['ans_content'], 'ans');
if (!$this->data['ans_content']) {
$this->throwMessage(ILLEGAL_IMAGE);
}
}
//默认执行回答提问方法
$func = 'addAnswer';
//需要的字段
$field = ['mem_id', 'mem_mark', 'mem_relation_id', 'que_id', 'ans_content'];
//根据可空回答id,empty_ans_id判断是否执行追问方法
if ($this->data['empty_ans_id']) {
array_push($field, $this->data['empty_ans_id']);
$func = 'addAnswerAsk';
}
//转义回答内容
$this->data['ans_content'] = mb_substr(\Func::escape($this->data['ans_content']), 0, 250, 'utf-8');
//获取执行状态,执行失败,并且是图片信息,则删除上传的图片
$add_status = $this->callModelFunc('Answer', $func, $field);
if ($add_status != OK && $this->data['is_img'] == 1) {
\FileUtil::getInstance()->unlink(PUBLIC_PATH . $this->data['ans_content']);
}
$this->throwMessage($add_status);
}
示例7: applyAction
/**
* 申请智囊
*/
public function applyAction()
{
//取值,参数验证,签名验证
$vars = ['mem_id', 'mem_mark', 'sage_realname', 'sage_cardid', 'sage_pic_above', 'sage_pic_below', 'tag_ides', 'sign'];
$this->beforeGetVarExecVerify($vars, 'post');
//生成身份证正反面图片
$this->data['sage_pic_above'] = \Func::touchImg($this->data['sage_pic_above'], 'sage');
$this->data['sage_pic_below'] = \Func::touchImg($this->data['sage_pic_below'], 'sage');
$images = [$this->data['sage_pic_above'], $this->data['sage_pic_below']];
if (!$this->data['sage_pic_above'] || !$this->data['sage_pic_below']) {
\FileUtil::getInstance()->unlink($images, PUBLIC_PATH);
$this->throwMessage(ILLEGAL_IMAGE);
}
//需要的字段
$field = ['mem_id', 'mem_mark', 'sage_realname', 'sage_cardid', 'sage_pic_above', 'sage_pic_below', 'tag_ides'];
$add_status = $this->callModelFunc('Sage', 'addSage', $field);
if ($add_status != OK) {
\FileUtil::getInstance()->unlink($images, PUBLIC_PATH);
}
$this->throwMessage($add_status);
}
示例8: registerAction
/**
* 注册接口
*/
public function registerAction()
{
$vars = ['mem_phone', 'pho_code', 'mem_account', 'mem_pwd', 'mem_head', 'login_system', 'login_number', 'mem_client_id', 'sign'];
$this->beforeGetVarExecVerify($vars, 'post');
//生产图片
$this->data['mem_head'] = \Func::touchImg($this->data['mem_head'], 'head');
if (!$this->data['mem_head']) {
$this->throwMessage(ILLEGAL_IMAGE);
}
//密码加密
$this->data['mem_pwd'] = $this->password($this->data['mem_pwd']);
//调用模型方法所需字段
$field = ['mem_phone', 'pho_code', 'mem_account', 'mem_pwd', 'mem_head', 'login_system', 'login_number', 'mem_client_id'];
//注册,并登陆,如果失败,删除上传的头像
$member = $this->callModelFunc('Member', 'register', $field);
if (!is_array($member)) {
\FileUtil::getInstance()->unlink(PUBLIC_PATH . $this->data['mem_head']);
$this->throwMessage($member);
}
$this->throwMessage(OK, $member);
}
示例9: addAction
/**
* 新增提问
*/
public function addAction()
{
//取值,参数验证,签名验证
$vars = ['mem_id', 'mem_mark', 'que_content', 'que_img', 'que_reward', 'tag_ides', 'sign'];
$this->beforeGetVarExecVerify($vars, 'post');
//图片操作
$this->data['que_img'] = json_decode($this->data['que_img'], true);
$this->data['que_img'] = is_array($this->data['que_img']) ? $this->data['que_img'] : [];
$images = [];
if (!empty($this->data['que_img'])) {
$i = 1;
foreach ($this->data['que_img'] as $key => $val) {
//数组格式不合法
if (!isset($val['img'])) {
\FileUtil::getInstance()->unlink($images, PUBLIC_PATH);
$this->throwMessage(ILLEGAL_ARRAY);
}
//非法的图片
if (!($images[] = \Func::touchImg($val['img'], 'que'))) {
\FileUtil::getInstance()->unlink($images, PUBLIC_PATH);
$this->throwMessage(ILLEGAL_IMAGE);
}
//控制提问最多可上传的数量
$i++;
if ($i > QUESTION_MAX_IMAGE) {
break;
}
}
}
//处理字段
$this->data['que_img'] = $images;
$this->data['que_content'] = \Func::escape($this->data['que_content']);
//所需字段
$field = ["mem_id", "mem_mark", "que_content", "que_img", "que_reward", "tag_ides"];
$add_status = $this->callModelFunc('Question', 'addQuestion', $field);
if ($add_status != OK) {
\FileUtil::getInstance()->unlink($images, PUBLIC_PATH);
}
$this->throwMessage($add_status);
}
示例10: newAction
/**
* 新增高校教师
*/
public function newAction($tra_id)
{
//判断是否ajax
if ($this->request->isAjax()) {
$validate = new \Validate();
$data['tra_id'] = $validate->getPost('tra_id', \Validate::int());
//学校id
$data['is_hot'] = $validate->getPost('is_hot', \Validate::int());
//热门
$data['tea_head'] = $validate->getPost('tea_head', \Validate::base64());
//教师头像
$data['tea_name'] = $validate->getPost('tea_name', \Validate::length(15, 2));
//教师名称
$data['tea_specialty'] = $validate->getPost('tea_specialty', \Validate::length(10, 2));
//教师专业
$data['tea_position'] = $validate->getPost('tea_position', \Validate::length(20, 2));
//教师职位
$data['tea_college'] = $validate->getPost('tea_college', \Validate::length(30, 2));
//毕业学校
$data['tea_sort'] = $validate->getPost('tea_sort', \Validate::length(99999999, 0));
//排序
$data['tea_summary'] = $validate->getPost('tea_summary', \Validate::length(255, 2));
//教师简介
//验证参数
if ($validate->getMessage()) {
$this->end(400);
}
//生成教师头像
$data['tea_head'] = \Func::touchImg($data['tea_head'], 'tea_head');
//监测图片是否生成成功
if (!$data['tea_head']) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $data['tea_head']);
$this->end(400);
}
//新增动态
$this->end((new \TrainTeacher())->addTeacher($this->session->get('id'), $data));
}
$this->view->setVars(['tra_id' => $tra_id]);
}
示例11: delTeacher
/**
* 删除高校教师
* @param int $man_id 管理员id
* @param int $sch_tea_id 小初高教师id
* @return int 删除状态
*/
public function delTeacher($man_id, $col_tea_id)
{
//检查教师是否存在
$sql = 'select col_tea_head from college_teacher where col_tea_id=? limit 1';
$result = $this->fetchOne($sql, [$col_tea_id]);
if (!$result) {
return 404;
}
//删除教师
$sql = 'delete from college_teacher where col_tea_id=:col_tea_id';
$this->execute($sql, ['col_tea_id' => $col_tea_id]);
if (!$this->affectedRows()) {
return 500;
}
//删除教师头像图片
if (is_file(UPLOAD_PATH . $result['col_tea_head'])) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $result['col_tea_head']);
}
//管理操作记录
$this->log($man_id, 'del_col_tea', '删除高校教师:', $col_tea_id);
return 200;
}
示例12: addAction
/**
* 添加阳光宝贝
*/
public function addAction($sch_id)
{
//判断是否ajax
if ($this->request->isAjax()) {
$validate = new \Validate();
$data['sch_id'] = $validate->getPost('sch_id', \Validate::int());
//学校id
$data['star_head'] = $validate->getPost('star_head', \Validate::base64());
//学员头像
$data['star_name'] = $validate->getPost('star_name', \Validate::length(15, 2));
//学员名称
$data['star_sort'] = $validate->getPost('star_sort', \Validate::length(99999999, 0));
//排序
// print_r($data);
//验证参数
if ($validate->getMessage()) {
$this->end(400);
}
//生成教师头像
$data['star_head'] = \Func::touchImg($data['star_head'], 'star_head');
//监测图片是否生成成功
if (!$data['star_head']) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $data['star_head']);
$this->end(400);
}
//新增动态
$this->end((new \Kindergarten())->addStar($this->session->get('id'), $data));
}
//加载js
$this->assets->addJs('backend/mt-js/kindergarten-star.js');
$this->view->setLayout('kindergarten');
$this->view->setVars(['sch_id' => $sch_id]);
}
示例13: detailAction
/**
* 新增学校课程
*/
public function detailAction($tra_id, $cou_id)
{
//检查是否是ajax请求
if ($this->request->isAjax()) {
$validate = new \Validate();
$data['tra_id'] = (int) $tra_id;
//学校ID
$data['cou_id'] = (int) $cou_id;
//课程ID
$data['cou_thumb'] = $validate->getPost('cou_thumb');
//学校缩略图
$data['spe_id'] = $validate->getPost('spe_id', \Validate::int());
//分类ID
$data['cou_name'] = $validate->getPost('cou_name', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{2,30}$/iu'));
//课程名称
$data['cou_sort'] = $validate->getPost('cou_sort', \Validate::int());
//课程排序
$data['cou_price'] = $validate->getPost('cou_price', \Validate::regex('/^[a-z0-9\\.\\/\\(\\)\\(\\)\\x{4e00}-\\x{9fa5}]{0,30}$/iu'));
//课程价格
$data['cou_system'] = $validate->getPost('cou_system', \Validate::int());
//上课类型
$data['is_hot'] = $validate->getPost('is_hot', \Validate::int());
//是否热门
$data['cou_summary'] = $validate->getPost('cou_summary', \Validate::nil(), ['slashes' => true]);
//课程简介
$data['cou_key'] = $validate->getPost('cou_key', \Validate::regex('/^[a-z0-9\\x{4e00}-\\x{9fa5}]{1,10}([\\s,][a-z0-9\\x{4e00}-\\x{9fa5}]{1,10}){0,9}$/iu'));
//关键词
$data['cou_desc'] = $validate->getPost('cou_desc', \Validate::length(250, 2), ['slashes' => true, 'html' => true]);
//描述
$data['cou_trait'] = $validate->getPost('cou_trait', \Validate::length(250, 2), ['slashes' => true, 'html' => true]);
//优势
$data['tea_id'] = $validate->getPost('tea_id');
$data['cou_addr'] = $validate->getPost('cou_addr');
//验证数据
if ($validate->getMessage()) {
$this->end(400);
}
//验证机构是否存在
if (!(new \Train())->getDetail($tra_id)) {
$this->end(404);
}
//生成课程缩略图
$cou_thumb = \Func::touchImg($data['cou_thumb'], 'cou_thumb');
//将生成的图片地址存入img,用户失败时删除
$img = [UPLOAD_PATH . $data['cou_thumb']];
//监测图片是否全部生成成功
if ($data['cou_thumb'] && !$cou_thumb) {
\FileUtil::getInstance()->unlink($img);
$this->end(400);
}
$data['cou_thumb'] = $cou_thumb;
//修改高校课程
$result = (new \Course())->UpdateCourse($this->session->get('id'), $data);
if ($result != 200) {
$this->end($result);
}
$this->end($result);
}
//获取参数
$cou_id = (int) $cou_id;
$tra_id = (int) $tra_id;
//获取详细信息
$detail = (new \Course())->getDetail($cou_id);
if ($detail == 404) {
$this->end(404);
}
//获取一级分类
$categorys = (new \Course())->getCategory();
//获取教师列表
$teachers = (new \TrainTeacher())->getTeacherList($tra_id)['list'];
//获取课程教师
$tea_id = (new \Course())->getTeacher($cou_id);
//获取地址列表
$cou_addr = (new \Course())->getAddress($cou_id);
$address = '';
foreach ($cou_addr as $val) {
$address .= ',' . $val['cou_add_content'];
}
//加载所需js
$this->assets->addJs('backend/js/editors/summernote/summernote.js');
$this->assets->addJs('backend/mt-js/bootstrap-tagsinput.js');
$this->assets->addJs('backend/mt-js/course-detail.js');
$this->view->setLayout('train');
$this->view->setVars(['detail' => $detail, 'tra_id' => $tra_id, 'categorys' => $categorys, 'teachers' => $teachers, 'tea_id' => $tea_id, 'cou_addr' => $cou_addr, 'address' => $address]);
}
示例14: delAlumnus
/**
* 删除高校教师
* @param int $man_id 管理员id
* @param int $sch_tea_id 小初高教师id
* @return int 删除状态
*/
public function delAlumnus($man_id, $col_alu_id)
{
//检查校友是否存在
$sql = 'select col_alu_head from college_alumnus where col_alu_id=? limit 1';
$result = $this->fetchOne($sql, [$col_alu_id]);
if (!$result) {
return 404;
}
//删除校友
$sql = 'delete from college_alumnus where col_alu_id=:col_alu_id';
$this->execute($sql, ['col_alu_id' => $col_alu_id]);
if (!$this->affectedRows()) {
return 500;
}
//删除校友头像图片
if (is_file(UPLOAD_PATH . $result['col_alu_head'])) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $result['col_alu_head']);
}
//管理操作记录
$this->log($man_id, 'del_col_alu', '删除知名校友:', $col_alu_id);
return 200;
}
示例15: delUnion
/**
* 删除合作机构数据
* @param int $man_id 管理员id
* @param int $uni_id 合作机构id
* @return int 删除状态
*/
public function delUnion($man_id, $uni_id)
{
//查询合作机构是否存在
$sql = 'select uni_logo from unions where uni_id=? limit 1';
$result = $this->fetchOne($sql, [$uni_id]);
if (!$result) {
return 404;
}
//删除合作机构数据
$sql = 'delete from unions where uni_id=?';
$this->execute($sql, [$uni_id]);
if (!$this->affectedRows()) {
return 500;
}
//删除合作机构logo图片
if (is_file(UPLOAD_PATH . $result['uni_logo'])) {
\FileUtil::getInstance()->unlink(UPLOAD_PATH . $result['uni_logo']);
}
$this->log($man_id, 'del_union', '删除合作机构:', $uni_id);
return 200;
}