免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1419 | 回复: 0
打印 上一主题 下一主题

发布系统后台代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-10-10 09:37 |只看该作者 |倒序浏览

很轻巧的发布系统代码
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');
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/1163/showart_51197.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP