//缩略图部分------------------------------------------------------------
//判断缩略图大小函数-----
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 $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
上传成功
;
}
//缩略图结束-----------------------------------------------------
}