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

    public function upload(){
    // 获取表单上传文件 例如上传了001.jpg
    $file = request()->file('image');
    $picture=model("Picture");
    $turepath = $file->getRealPath();
    $md5path=md5_file($turepath);
    $shalpath=sha1_file($turepath);
    $map["md5"]=$md5path;
    $map["sha1"]=$shalpath;
    /*判断是否有相同图片上传过了*/
    $image=$picture->find($map);
    if($image){
    $this->output_data(200,'success',array('img'=>'http://'.$_SERVER['HTTP_HOST'].$image["path"],"id"=>$image["id"]));
    }
    //判断文件类型
    if(!count($file)){
    $this->output_data(-1,'图片不能为空!');
    }
    $type=$file->checkImg();
    if(!$type){
    $this->output_data(-1,'图片类型不正确!');
    }

    // 移动到框架应用根目录/public/uploads/ 目录下
    $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
    if($info){
    $path = $info->getSaveName();
    $data=array();
    $img_path='http://'.$_SERVER['HTTP_HOST'].'/uploads/'.$path;
    $type=$info->getExtension();
    $type="image/".$type;
    $data["path"]='/uploads/'.$path;
    $data["type"]=$type;
    $data["status"]=1;
    $data["md5"]=$md5path;
    $data["sha1"]=$shalpath;

    $result=$picture->insert($data);
    $this->output_data(200,'success',array('img'=>$img_path,"id"=>$result));
    /*echo $path;
    echo "<br>";
    // 输出 42a79759f284b767dfcb2a0197904287.jpg
    echo $info->getFilename();
    echo "<br>";
    输出 42a79759f284b767dfcb2a0197904287.jpg*/
    echo $info->getPathName();
    }else{
    // 上传失败获取错误信息
    $this->output_data(-1,'提交失败!');
    }
    }
  • 相关阅读:
    html5阴影
    html5绘制字符串
    HTML5绘制几何图形
    Animation同时改变多个属性的动画
    Animation鱼眼效果
    Animation动画
    IE6中CSS常见BUG全集及解决方案——摘自网友
    transition多个属性同时渐变(width,height,background)
    【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测
    【CF995F】 Cowmpany Cowmpensation
  • 原文地址:https://www.cnblogs.com/xqschool/p/5893661.html
Copyright © 2011-2022 走看看