zoukankan      html  css  js  c++  java
  • PHP图片上传方法

    /**
     * 验证图片
     * @params array $images,int $id,string $poster_path
     * @return array
     */
    function checkImg($images,$id,$poster_path) {
        $msg  = '';
        $path = '';
        //验证图片大小
        if(isset($images) && $images['error'] == 0) {
            if($images['size']>1024*700){
                $msg = '图片不能超过700K';
            }else {
                $type = pathinfo($images['name'], PATHINFO_EXTENSION);
                if ($type != "png" && $type != 'jpg' && $type != 'jpeg') {
                    $msg = "请上传正确格式的图片";
                }
                $time = time();
                $file = "poster_{$time}.$type";
                $path = "upload/junior/poster";
                $upload = ROOT_PATH . "/Html/{$path}/{$file}";
                if(!is_dir(ROOT_PATH . "/Html/{$path}")) {
                    mkdir(ROOT_PATH . "/Html/{$path}", 0777, true);
                }
                move_uploaded_file($images['tmp_name'], $upload);
                $path = "{$path}/{$file}";
            }
        }elseif($id != 0){
            $path = $poster_path;
        }else {
            $msg = '图片不能为空且图片大小不能超过700K';
        }
        return $res = array('msg' => $msg , 'path' => $path);
    }
  • 相关阅读:
    数据导入和导出
    用户登陆案例
    SQLHelper
    把连接数据库的字符串放在配置文件中
    访问数据库
    SQL语句
    Django Tornado Flask
    Python 的协程
    面试 Better Call Soul
    mklink 解决VScode 扩展...Google迁移到 windows D盘
  • 原文地址:https://www.cnblogs.com/yeshaoxiang/p/7827260.html
Copyright © 2011-2022 走看看