PHP之图片上传类(加了缩略图),_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP之图片上传类(加了缩略图),_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3137字,纯文字阅读大概需要5分钟。
内容图文
![PHP之图片上传类(加了缩略图),_PHP教程](/upload/InfoBanner/zyjiaocheng/192/1da9fd4d34f5488d93270251909b9bf2.jpg)
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_...
内容总结
以上是互联网集市为您收集整理的PHP之图片上传类(加了缩略图),_PHP教程全部内容,希望文章能够帮你解决PHP之图片上传类(加了缩略图),_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。