21,893
社区成员




<?php
//需要GD库支持
function createsmallpic($oldpicpath,$savepath,$wh,$ww) {
$imgQuality=100;//图片质量
$max_height=$wh;//生成图片的高度
$max_width=$ww;//生成图片的宽度
$data=GetImageSize($oldpicpath);
@$small = imagecreatetruecolor($width,$height);
@$oldim = imagecreatefromstring(file_get_contents($oldpicpath));
imagecopyresampled($small,$oldim,0,0,0,0,$width,$height,imagesx($oldim),imagesy($oldim));
switch($data[2]){
case 'gif':ImagePNG($small,$savepath,100); break;
case 'jpeg':imagejpeg($small,$savepath,100); break;
case 'png':ImagePNG($small,$savepath,100); break;
default:imagejpeg($small,$savepath,100); break;
}
}
/////////////////////////////
$uploaddir = 'UPLOADS/';//文件存放路径
$temploadfile = $_FILES['File']['tmp_name'];
if($temploadfile !=""){
$temptype = end(explode(".",$_FILES['File']['name']));}
$A=$uploaddir.date("YmdHis").".".$temptype;//构造文件名
$B=$uploaddir.date("YmdHis")."s.".$temptype;//小圖
if(move_uploaded_file($temploadfile, $A))
{
createsmallpic($uploaddir.$A,$uploaddir.$B,"200","100");
}
?>