发布系统后台代码
时间:2005-10-10 来源:ilcj
很轻巧的发布系统代码
alert("'.$msg.'");';
}
if($_POST)
{
//print_r($_POST);
extract($_POST);
if($_POST['type']=='save')
{
$param = array();
$sql = "select * from new_index";
$db->sql_query($sql) or exit(mysql_error());
$data = $db->sql_fetchrowset();
$db->sql_freeresult();
foreach($data as $item)
{
list($id,$text,$link)=$item;
//print_r($item);
$param[$id]=compact("text","link");
}
$tpl->assign($param);
ob_start();
$tpl->display('music_index.tpl');
$content = ob_get_contents();
ob_clean();
@unlink('/home/web/xtv/process/music_index.htm.new');
$fp = fopen('music_index.htm.new','wb');
if(fwrite($fp,$content))alert('更新成功!');
else alert('更新失败!');
fclose($fp);
rename('music_index.htm.new','/home/web/xtv/process/music_index.htm');
}
elseif($_POST['type']=='upload')
{
if($id=='')die('id错误');
//print_r($_FILES);
$sql ="select `id` from new_index where `id`='$id'";
$db->sql_query($sql) or die(mysql_error());
if(!$db->sql_numrows())
{
$sql="insert into new_index(`id`,`text`,`link`) values ('$id','','');";
$db->sql_query($sql);
}
$file_type = $_FILES['upfile']['type'];
$value = '';
if($file_type!='' && !ereg("^image/.*",$file_type))
{
die('上传文件只能是图片');
}
elseif($file_type!='')
{
$tmp_name = $_FILES['upfile']['tmp_name'];
$filename = $_FILES['upfile']['name'];
$filenameinfo = explode('.',$filename);
$file_ext = $filenameinfo[count($filenameinfo)-1];
$upload_dir='./tmp/';
$file_path = $upload_dir.$id.'.'.$file_ext;
if(move_uploaded_file($tmp_name,$file_path))
{
$text = $file_path;
}
else
{
die('上传失败!');
}
}
$update = "link='$link'";
if($text!='')$update .= ",text='$text'";
$condition = "id='$id'";
$sql = "update new_index set $update where $condition";
//echo $sql;
$db->sql_query($sql) or exit($sql.mysql_error());
}
elseif($_POST['type']=='edit')
{
if($id=='')die('id错误');
$sql ="select `id` from new_index where `id`='$id'";
$db->sql_query($sql);
if(!$db->sql_numrows())
{
$sql="insert into new_index(`id`,`text`,`link`) values ('$id','','');";
$db->sql_query($sql);
}
if($text=='')die('文字不能为空');
$update = "text='$text',link='$link'";
$condition = "id='$id'";
$sql = "update new_index set $update where $condition";
//echo $sql;
$db->sql_query($sql) or exit($sql.mysql_error());
}
else
{
die('未知操作类型');
}
//print_r($_POST);
}
$param = array();
for($i=0;$i'','link'=>'http://www.***.com');
$param['top'.$i]=array('text'=>'测试文字','link'=>'http://www.****.com');
}
$sql = "select * from new_index";
$db->sql_query($sql) or exit(mysql_error());
$data = $db->sql_fetchrowset();
$db->sql_freeresult();
foreach($data as $item)
{
list($id,$text,$link)=$item;
//print_r($item);
$param[$id]=compact("text","link");
}
$tpl->assign($param);
$tpl->display('music_admin.tpl');
?>
相关阅读 更多 +