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

    /*图片上传*/
        public function upload(){
            $file = $_FILES['mypic'];
            $upload = new ThinkUpload();// 实例化上传类
            $upload->maxSize = 2*1024*1024;
            $upload->rootPath  = './Uploads/'; // 设置附件上传根目录
            $upload->savePath  = 'Advert/yyzz/'; // 设置附件上传(子)目录
            $upload->exts     = array('jpg', 'jpeg','png');
            $info = $upload->uploadOne($file);
            $infourl='./Uploads/'.$info['savepath'].$info['savename'];
            $image = new ThinkImage();
            $image->open($infourl);//将图片裁剪为400x400并保存为corp.jpg
            $width = $image->width(); // 返回图片的宽度
            $height = $image->height(); // 返回图片的高度
            $iw = $ih = 150;
            if($iw>$width){
                $iw = $width;
            }
            if($ih>$height){
                $ih = $height;
            }
            if($width>150 || $height>150){
                $image->thumb($iw, $ih,ThinkImage::IMAGE_THUMB_CENTER)->save($infourl);
            }
            if($info){
                $data['imgurl']='./Uploads/'.$info['savepath'].$info['savename'];
                $res=M('image')->add($data);
                if($res){
                    exit('{"name":"'.$info['savename'].'","imgurl":"'.$data['imgurl'].'","imgid":"'.$res.'"}');
                }
            }else{
                exit;
            }
    
        }
  • 相关阅读:
    1343. Fairy Tale
    Codeforces Beta Round #97 (Div. 1)
    URAL1091. Tmutarakan Exams(容斥)
    1141. RSA Attack(RSA)
    hdu4003Find Metal Mineral(树形DP)
    hdu2196 Computer待续
    KMP
    莫比乌斯反演
    配对堆
    bzoj3224Treap
  • 原文地址:https://www.cnblogs.com/finnlee/p/5045530.html
Copyright © 2011-2022 走看看