• php图片上传


    //处理图片
    private function imageDeal($param){
    $arrType=array('image/jpg','image/bmp','image/png','image/jpeg');
    $max_size=2*1024*1024;
    if(!empty($param['name'])){
    if($param['error']>0){
    //echo "<script>alert('上传错误!');window.location.href='/index.php?m=member&c=sysrestr&a=index';</script>";
    //echo 'aaaaaaaaaaaa';die;
    $this->error('上传错误!','/Home/Baoming/oindex',2);
    }else{
    if(!in_array($param['type'],$arrType)){ //判断图片文件的格式
    //echo "<font color='#FF0000'>上传文件格式不对!</font>";
    // echo "<script>alert('上传文件格式不对!');window.location.href='/index.php?m=member&c=sysrestr&a=index';</script>";
    //echo 'bbbbb';die;
    $this->error('上传错误!','/Home/Baoming/oindex',2);
    }else{
    switch($param['type'])
    {
    case 'image/jpg':
    $ext = '.jpg';
    break;
    case 'image/bmp':
    $ext = '.bmp';
    break;
    case 'image/jpeg':
    $ext = '.jpg';
    break;
    case 'image/png':
    $ext = '.png';
    break;
    default:
    //echo 'The file you uploaded was not a supported filetype.';
    break;
    }
    }
    $xt = md5(strtotime(date('Y-m-d H:i:s')).mt_rand(0,100));
    if(file_exists("Baoming/images/upload/".$xt.$ext)){

    $this->error('上传已经存在!','/Home/Baoming/oindex',2);
    //return FALSE;
    }else{
    if(is_uploaded_file($param['tmp_name'])){
    $stored_path = 'Baoming/images/upload/'.$xt.$ext;
    //echo $stored_path ;die;

    if(move_uploaded_file($param['tmp_name'],$stored_path)){
    $imgurl = $stored_path;
    }else{
    //echo 'cccc';die;
    $this->error('上传错误!','/Home/Baoming/oindex',2);

    }
    }else{
    //echo 'ccdddddcc';die;
    $this->error('上传错误!','/Home/Baoming/oindex',2);

    }
    }
    }
    }


    return $imgurl;
    }

    然后调用即可。

  • 相关阅读:
    nginx解决跨域问题
    SSM整合相关试题
    SSM整合案例--用户登录
    非法用户登录拦截
    SpringMVC拦截器和数据校验
    SpringMVC文件上传
    SpringMVC异常处理
    SpringMVC方法的返回值类型和自动装配
    SpringMVC
    spring和mybatis整合
  • 原文地址:https://www.cnblogs.com/yaoyao1556/p/5242915.html
Copyright © 2020-2023  润新知