Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1216133
  • 博文数量: 275
  • 博客积分: 6445
  • 博客等级: 准将
  • 技术积分: 2863
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-04 23:22
文章分类

全部博文(275)

文章存档

2024年(4)

2023年(5)

2022年(3)

2021年(18)

2020年(9)

2019年(1)

2018年(13)

2017年(11)

2015年(9)

2013年(2)

2012年(4)

2011年(24)

2010年(114)

2009年(6)

2008年(29)

2007年(13)

2006年(10)

我的朋友

分类: LINUX

2010-07-06 10:33:34

$title = $_POST['title'];
$descrīption = $_POST['descrīption'];
$albumID = $_POST['albumID'];
$iscommend = $_POST['iscommend'];
$isvisible = $_POST['isvisible'];
$uploadtime = date("Y-m-d H:i:s");
$MAX_FILE_SIZE = floor($_POST['MAX_FILE_SIZE'] / 1024);

$FileExtName = strtolower(pathinfo($_FILES['url']['name'],PATHINFO_EXTENSION));
if(!(($FileExtName == 'gif') or ($FileExtName == 'jpg') or ($FileExtName == 'jpeg') or ($FileExtName == 'png'))){
    echo "";
echo " alert('您上传的文件类型不对,本系统仅支持PNG,JPG,GIF三种格式。');";
echo " location='../uploadpicture.php?albumID=$albumID';";
echo "
";
exit;
}
$Filename = date("YmdHis").substr(microtime(),2,5).'.'.$FileExtName;
$PictureDir = substr(pathinfo($_SERVER['scrīpt_FILENAME'],PATHINFO_DIRNAME),0,strlen(pathinfo($_SERVER['scrīpt_FILENAME'],PATHINFO_DIRNAME))-8);
$UploadURL = $PictureDir.'/'.$PictureFolder.$Filename;
$ThumbsURL = $PictureDir.'/'.$ThumbsFolder.$Filename;
if (!move_uploaded_file($_FILES['url']['tmp_name'], $UploadURL)){
    echo "";
echo " alert('上传失败,图片大小不能超过 $MAX_FILE_SIZE KB。');";
echo " location='../uploadpicture.php?albumID=$albumID';";
echo "
";
exit;
}
list($RealWidth, $RealHeight) = getimagesize($UploadURL);
if($RealWidth < $MaxThumbWidth){
$percent = 1;
} else {
$percent = $MaxThumbWidth / $RealWidth;
}
$NewWidth = $RealWidth * $percent;
$NewHeight = $RealHeight * $percent;
$thumb = imagecreatetruecolor($NewWidth, $NewHeight);
list($width, $height, $PictureType, $attrib) = getimagesize($UploadURL);
switch($PictureType)
{
   case "1": $source = imagecreatefromgif($UploadURL); break;
   case "2": $source = imagecreatefromjpeg($UploadURL); break;
   case "3": $source = imagecreatefrompng($UploadURL); break;
}
imagecopyresized($thumb, $source, 0, 0, 0, 0, $NewWidth, $NewHeight, $RealWidth, $RealHeight);
switch($PictureType)
{
   case "1": imagegif($thumb, $ThumbsURL); break;
   case "2": imagejpeg($thumb, $ThumbsURL); break;
   case "3": imagepng($thumb, $ThumbsURL); break;
}

$newpicture_SQL = "INSERT INTO pictures (flag,title,url,descrīption,uploadtime,updatetime,isvisible,iscommend) VALUES ('$albumID','$title','$Filename','$descrīption','$uploadtime','$uploadtime','$isvisible','$iscommend');";
$setCover = "Update pictures SET url = '$Filename' WHERE id = $albumID;";
$totalPictures_SQL = "SELECT * FROM pictures WHERE flag = $albumID;";
$totalPictures = mysql_query($totalPictures_SQL, $hesweb) or die(mysql_error());
$totalRows_totalPictures = mysql_num_rows($totalPictures);
$newpicture = mysql_query($newpicture_SQL, $hesweb) or die(mysql_error());
$pictureID = mysql_insert_id($hesweb);
$coverFlag = "UPDATE pictures SET iscover = '1' WHERE id = $pictureID;";
if($totalRows_totalPictures < 1){
     $cover = mysql_query($setCover, $hesweb) or die(mysql_error());
$flag = mysql_query($coverFlag, $hesweb) or die(mysql_error());
}
if($coverFlag){
    echo "";
echo " alert('上传成功。');";
echo " location='../uploadpicture.php?albumID=$albumID';";
echo "
";
}
?>

阅读(3066) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~