<?
@require_once('../inc/fun.inc.php');
@require_once('../inc/config.db.php');
@require_once('../inc/suo.php');
@require_once('cookie.php');
?>
<?
$id = $_GET["id"];
trim($title = $_POST["title"]);
trim($ze = $_POST["ze"]);
trim($ly = $_POST["ly"]);
$lb= $_POST["lb"];
$content = $_POST["content"];
if(empty($title) || empty($ze) || empty($ly) || empty($lb) || empty($content))
{
	msg($wtime,"admin.php?main=cp","表单不能为空请返回");
	exit;
}
$page=$_GET['page'];
if(empty($page)){
$page=1;
}
if(empty($_FILES["file"]['name']))
{
	$sql="update cp set title='$title',author='$ze',source='$ly',content='$content',cplbid='$lb' where id='$id'";
	$result = mysql_query($sql);
	if($result)
	{
		msg($wtime,"admin.php?main=cp","修改成功");
		exit;
	}else
	{
		msg($wtime,"admin.php?main=cp","非法操作请返回");
		exit;
	}
	  
}else
{
if($_FILES["file"]['error']>0)
{header("Location: admin.php?main=cp"); 
exit;}
$d=rand(10,999999999);
move_uploaded_file($_FILES["file"]['tmp_name'],'../pic/'.$d.$_FILES["file"]['name']);
$a=$d.$_FILES["file"]['name'];
$m=new Miniature();
$m->ReadImage('../pic/'.$a);
$m->ResizeImage(234,164);//智能缩小
$m->LoadFont("arial.ttf");
$w=$m->ImageWidth;
$h=$m->ImageHeight;
$m->ImageType=1;//保存成gif格式
$ak=rand(10,999999999);
$ak1=rand(10,999999999);
$suo_name1=$ak.$ak1;
$m->SaveImage("../pic/",$suo_name1);//保存图片,"To/":保存路径,"demo_1":图片名称
$m->DestroyImage();//销毁图片   
unlink("../pic/".$a);
$url="pic/".$suo_name1.".gif";	
$sql="select * from cp where id='$id'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
unlink('../'.$row['url']);  
	$sql="update cp set title='$title',author='$ze',source='$ly',content='$content',url='$url',cplbid='$lb' where id='$id'";
	$result = mysql_query($sql);
	if($result)
	{
		msg($wtime,"admin.php?main=cp","修改成功");
		exit;
	}else
	{
		msg($wtime,"admin.php?main=cp","非法操作请返回");
		exit;
	}     
}
?>