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);
    }
  • 相关阅读:
    SQL 拾遗
    PowerDesigner技巧
    进步
    'data.csv'
    System.Web”中不存在类型或命名空间名称script /找不到System.Web.Extensions.dll引用
    要学的技术
    Sql 表变量
    Tomcat 7.0的配置
    开发工具
    jQuery UI Dialog
  • 原文地址:https://www.cnblogs.com/yeshaoxiang/p/7827260.html
Copyright © 2011-2022 走看看