php之图片上传类(加了缩略图),有缩略图功能 但是 感觉不全面,而且有点问题,继续学习,将来以后修改下
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){ $imgatt=getimagesize($this->path); //图像宽,高,类型 $imgwidth=$imgatt[0]; $imgheight=$imgatt[1]; $imgext=$imgatt[2]; //等比列缩放 if(($x/$imgwidth)>($y/$imgheight)){ $bl=$y/$imgheight; }else{ $bl=$x/$imgwidth; } $x=floor($imgwidth*$bl); //缩放后 $y=floor($imgheight*$bl); $images=imagecreatetruecolor($x,$y); $big=imagecreatefromjpeg($this->path); imagecopyresized($images,$big,0,0,0,0,$x,$y,$imgwidth,$imgwidth); switch($imgext){ 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 ;echo ;?>
examples
http://www.bkjia.com/phpjc/1138633.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1138633.htmltecharticlephp之图片上传类(加了缩略图), 有缩略图功能 但是 感觉不全面,而且有点问题,继续学习,将来以后修改下 form action=?php $_server['php_...