找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1271|回复: 0
打印 上一主题 下一主题

PHP之图片上传类实例代码(加了缩略图)

[复制链接]

2487

主题

2487

帖子

7391

积分

论坛元老

Rank: 8Rank: 8

积分
7391
跳转到指定楼层
楼主
发表于 2018-2-14 05:34:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            有缩略图功能 但是 感觉不全面,而且有点问题,继续学习,将来以后修改下
" enctype="multipart/form-data" method="post" >

filename=$filename;
    $this->fileinfo=$_FILES[$this->filename];
    $this->filemax=$filemax;
    $this->filepath=$filepath;
    $this->fileflag=$fileflag;
    $this->fileExt=$fileExt;
    $this->fileMine=$fileMine;

    //var_dump($this->filename);

  }

  //错误判断
  public function UpError(){

      if($this->fileinfo['error']>0){
        switch($this->fileinfo['error'])
        {
          case 1:
          $this->fileerror="上传文件大小超过服务器允许上传的最大值,php.ini中设置upload_max_filesize选项限制的值 ";
            break;
          case 2:
            $this->fileerror="上传文件大小超过HTML表单中隐藏域MAX_FILE_SIZE选项指定的值";
            break;
          case 3:
            $this->fileerror="文件部分被上传";
            break;
          case 4:
            $this->fileerror="没有选择上传文件";
            break;
          case 5:
            $this->fileerror="未找到临时目录";
            break;
          case 6:
            $this->fileerror="文件写入失败";
            break;
          case 7:
            $this->fileerror="php文件上传扩展没有打开 ";
            break;
          case 8:
            $this->fileerror="";
            break;

        }
        return false;
      }
      return true;

  }

  //检测文件类型
  public function UpMine(){
    if(!in_array($this->fileinfo['type'],$this->fileMine)) {
      $this->error="文件上传类型不对";
      return false;
    }
    return true;

  }
  //检测文件格式
  public function UpExt(){
    $this->ext=pathinfo($this->fileinfo['name'],PATHINFO_EXTENSION);
    //var_dump($ext);
    if(!in_array($this->ext,$this->fileExt)){
      $this->fileerror="文件格式不对";
      return false;
    }
    return true;
  }
  //检测文件路径
  public function UpPath(){
    if(!file_exists($this->filepath)){
      mkdir($this->filepath,0777,true);
    }
  }
  //检测文件大小
  public function UpSize(){
    $max=$this->fileinfo['size'];
    if($max>$this->filemax){
      $this->fileerror="文件过大";
      return false;
    }
    return true;
  }
  //检测文件是否HTTP
  public function UpPost(){
    if(!is_uploaded_file($this->fileinfo['tmp_name'])){
      $this->fileerror="恶意上偿还";
      return false;
    }
    return true;
  }
  //文件名防止重复
  public function Upname(){
    return md5(uniqid(microtime(true),true));
  }

  //图片缩略图
  public function Smallimg($x=100,$y=100){
    $($this->path);
    //图像宽,高,类型
    $$[0];
    $$[1];
    $$[2];
    //等比列缩放

    if(($x/$)>($y/$)){
      $bl=$y/$;
    }else{
      $bl=$x/$;
    }
    $x=floor($*$bl); //缩放后
    $y=floor($*$bl);
    $images=imagecreatetruecolor($x,$y);
    $big=imagecreatefromjpeg($this->path);
    imagecopyresized($images,$big,0,0,0,0,$x,$y,$,$);
    switch($){
      case 1:
        $imageout=imagecreatefromgif($this->path);
        break;
      case 2:
        $imageout=imagecreatefromjpeg($this->path);
        break;
      case 3:
        $imageout=imagecreatefromgif($this->path);
        break;
    }
    $im=imagejpeg($images,$this->path);




  }

  //文件双传
  public function uploads()
  {
    if($this->UpError()&&$this->UpMine()&&$this->UpExt()&&$this->UpSize()&&$this->UpPost()){
      $this->UpPath();
      $names=$this->Upname();
      $this->path=$this->filepath.'/'. $names.'.'.$this->ext;

      if(move_uploaded_file($this->fileinfo['tmp_name'], $this->path)){
        return $this->path;
      }else{
        $this->fileerror="上传失败";
      }
    }else{
      exit("".$this->fileerror."");
    }
  }


}


?>
uploads();

$c=$u->Smallimg();
echo "
[img][/img]
";
echo "
[img][/img]
";

?>





Examples





   
  
  
   

以上这篇PHP之图片上传类实例代码(加了缩略图)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
            
            
您可能感兴趣的文章:
  • PHP图片上传类带图片显示
  • php 图片上传类代码
  • php 图片加水印与上传图片加水印php类
  • 超级好用的一个php上传图片类(随机名,缩略图,加水印)
  • php另类上传图片的方法(PHP用Socket上传图片)
  • PHP实现多图片上传类实例
  • php上传图片类及用法示例
  • php图片上传类 附调用方法
  • PHP上传图片类显示缩略图功能
  • php封装的单文件(图片)上传类完整实例
  • PHP实现原生态图片上传封装类方法
  • php版阿里云OSS图片上传类详解
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端