电脑安全

您当前的位置:主页 > 电脑安全 >

php 判断上传图大小函数-网络编程

来源:[db:来源]标题:   缩略图    编辑:电脑技术全能网 时间:2019-09-21 12:23

原标题:php 判断上传图大小函数-网络编程
   //缩略图局部------------------------------------------------------------//推断缩略图巨细函数----- function ResizeImage($im,$maxwidth,$maxheight,$name){ $width = imagesx($im); $height = imagesy($im); if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ if($maxwidth && $width > $maxwidth){ $widthratio = $maxwidth/$width; $RESIZEWIDTH=true; } if($maxheight && $height > $maxheight){ $heightratio = $maxheight/$height; $RESIZEHEIGHT=true; } if($RESIZEWIDTH && $RESIZEHEIGHT){ if($widthratio < $heightratio){ $ratio = $widthratio; }else{ $ratio = $heightratio; } }elseif($RESIZEWIDTH){ $ratio = $widthratio; }elseif($RESIZEHEIGHT){ $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg ($newim,$smalladdrname.$name.".jpg"); ImageDestroy ($newim); }else{ ImageJpeg ($im,$smalladdrname.$name.".jpg"); } } //天生局部 if($_FILES['image']['size']){ if($_FILES['image']['type'] == "image/pjpeg"){ $im = imagecreatefromjpeg($bigaddrname.$exname); }elseif($_FILES['image']['type'] == "image/x-png"){ $im = imagecreatefrompng($bigaddrname.$exname); }elseif($_FILES['image']['type'] == "image/gif"){ $im = imagecreatefromgif($bigaddrname.$exname); } if($im){ if(file_exists($smalladdrname.".jpg")){ unlink($smalladdrname.".jpg"); } ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$smalladdrname); ImageDestroy ($im); } } echo "<div align='center'><a href='javascript:window.history.back()'>上传胜利</a></div>";}//缩略图停止----------------------------------------------------- }

上一篇:PHP 挑战 J2EE 和 .NET-网络编程

下一篇:没有了