PHP图片上传类实例代码分享
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要讲解了"PHP图片上传类实例代码分享",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"PHP图片上传类实例代码分享"吧!" enctype="
千家信息网最后更新 2026年11月01日PHP图片上传类实例代码分享
这篇文章主要讲解了"PHP图片上传类实例代码分享",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"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
感谢各位的阅读,以上就是"PHP图片上传类实例代码分享"的内容了,经过本文的学习后,相信大家对PHP图片上传类实例代码分享这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
文件
图片
检测
代码
实例
大小
类型
学习
不对
内容
格式
最大
图像
就是
思路
恶意
情况
文件名
文章
更多
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
百单网互联网科技有限公司怎么样
广东万易互联网科技有限公司惠州分公司
广州大一互联网络科技有限公司
互联网科技巨头监管
互联网 科技公司
互联网络科技有限公司
碳银互联网科技
顺玮阁互联网科技
融贸通互联网科技
新华互联网科技校企合作
速维有品互联网信息科技(苏州)有限公司
互联网科技扶贫时间
山东有哪些互联网科技公司
众安科技工业互联网合作
江苏苏星互联网科技有限公司
城市宝互联网科技有限公司
风投北京互联网科技
神州科技互联网有限公司
容联科技互联网电商
盐城市攀科互联网科技有限公司
互联网科技有限公司
喔噻互联网科技有限公司
涨乐互联网科技
互联网科技战争
互联网科技英文翻译
移动互联网科技股
深圳艾果互联网通讯科技
工业互联网山东科技大学
山东星卡互联网科技有限公司官网
江苏互联网智能科技产品出厂价