2022年PHP缩略图图片上传代码 .pdf
HTML 页面提交 UpLoad.php 页面调用方式GetSize()$UpFileSize)$T1=Null;Echo alert(请修改 Logo 图片小于.$UpFileSize.Byte,再编辑该条信息重新上传!);ElseIf($UpFos-GetExt()!=jpg&$UpFos-GetExt()!=jpeg&$UpFos-GetExt()!=gif&$UpFos-GetExt()!=png)&$UpFos-GetExt()!=)$T1=Null;Echo alert(只能上传jpg/jpeg/gif/png格式的Logo 图片!请修改格式后,再编辑该条信息重新上传!);Else/上传文件以新名字命名$UpFos-UpLoad($UpFos-NewName();/获得上传图片路径$T1=Str_Replace(./,$UpFos-FilePath();/生成缩略图有 3 种方式自己看组件函数$UpFos-Thumb(,320,240);/获得缩略图路径$T1_1=Str_Replace(./,$UpFos-ThumbMap();/变量$T1$T1_1 可以直接写入数据库存储Echo alert(上传图片成功);location.href=设置上传完成想跳转的页面;?名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 10 页 -GDUpLoad.Class.inc 文件代码$width/$height)/高比较大$W=$width;$H=$srcH*$width/$srcW;$IntNH=$H-$height;imagecopyresized($ni,$im,0,-$IntNH/1.8,0,0,$width,$H,$srcW,$srcH);Else/宽比较大$H=$height;$W=$srcW*$height/$srcH;$IntNW=$W-$width;imagecopyresized($ni,$im,-$IntNW/1.8,0,0,0,$W,$height,$srcW,$srcH);$cr=imagejpeg($ni,$dscFile,90);chmod($dscFile,0777);If($cr)$Sm_File=$dscFile;return true;Else$Error=5;return$Error;/创建图片缩略图方式二(不变形截取)Function Thumb1($dscChar=,$width,$height)global$CanUpload,$Error,$Directroy,$DoUpFile,$Sm_File;If($CanUpload&$DoUpFile!=)$srcFile=$DoUpFile;If($dscChar=)$dscChar=sm_;名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 10 页 -$dscFile=$Directroy.$dscChar.$srcFile;$data=getimagesize($Directroy.$srcFile,&$info);switch($data2)case 1:$im=imagecreatefromgIf($Directroy.$srcFile);Break;case 2:$im=imagecreatefromjpeg($Directroy.$srcFile);Break;case 3:$im=imagecreatefrompng($Directroy.$srcFile);Break;$srcW=imagesx($im);$srcH=imagesy($im);If($srcW/$width)=($srcH/$height)$temp_height=$height;$temp_width=$srcW/($srcH/$height);$src_X=abs($width-$temp_width)/2);$src_Y=0;Else$temp_width=$width;$temp_height=$srcH/($srcW/$width);$src_X=0;$src_Y=abs($height-$temp_height)/2);$temp_img=imagecreatetruecolor($temp_width,$temp_height);imagecopyresized($temp_img,$im,0,0,0,0,$temp_width,$temp_height,$srcW,$srcH);$ni=imagecreatetruecolor($width,$height);imagecopyresized($ni,$temp_img,0,0,$src_X,$src_Y,$width,$height,$width,$height);$cr=imagejpeg($ni,$dscFile);chmod($dscFile,0777);If($cr)$Sm_File=$dscFile;Return true;Else 名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 10 页 -$Error=5;Return$Error;/创建图片缩略图方式三(变形全显)Function Thumb2($dscChar=,$width,$height)global$CanUpload,$Error,$Directroy,$DoUpFile,$Sm_File;If($CanUpload&$DoUpFile!=)$srcFile=$DoUpFile;If($dscChar=)$dscChar=sm_;$dscFile=$Directroy.$dscChar.$srcFile;$data=getimagesize($Directroy.$srcFile,&$info);switch($data2)case 1:$im=imagecreatefromgif($Directroy.$srcFile);Break;case 2:$im=imagecreatefromjpeg($Directroy.$srcFile);Break;case 3:$im=imagecreatefrompng($Directroy.$srcFile);Break;$srcW=imagesx($im);$srcH=imagesy($im);$ni=imagecreatetruecolor($width,$height);imagecopyresized($ni,$im,0,0,0,0,$width,$height,$srcW,$srcH);$cr=imagejpeg($ni,$dscFile);chmod($dscFile,0777);If($cr)$Sm_File=$dscFile;名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 10 页 -return true;Else$Error=5;return$Error;/显示错误参数Function Err()global$Error;return$Error;/上传后的文件名Function UpFile()global$DoUpFile,$Error;If($DoUpFile!=)return$DoUpFile;Else$Error=6;/上传文件的路径Function FilePath()global$Directroy,$DoUpFile,$Error;If($DoUpFile!=)return$Directroy.$DoUpFile;Else$Error=6;/缩略图文件名称Function ThumbMap()global$Sm_File,$Error;If($Sm_File!=)名师资料总结-精品资料欢迎下载-名师精心整理-第 9 页,共 10 页 -return$Sm_File;Else$Error=6;/显示版本信息Function Version()return GDUpLoad;?名师资料总结-精品资料欢迎下载-名师精心整理-第 10 页,共 10 页 -