0 Comments

新增广告操作

发布于:2012-11-26  |   作者:广州网站建设  |   已聚集:人围观
增广告操作

新增广告操作的核心是处理新增广告表单中的数据,处理后的数据写入广告数据存放文本(data.txt)中。下面来看页面表单的部分,核心的表单代码如下:

广州网站建设
  1. <div align="left"> 
  2. <table width="100%" border="1" cellpadding="3" cellspacing="0" 
  3.     bgcolor="#CCCCCC"> 
  4.     <tr> 
  5.         <td width="16%">广告ID:<font color="#FF0000">*</font><br> 
  6.         <br> 
  7.         </td> 
  8.         <td width="84%"><input name="id" type="TEXT" class="input" 
  9.             id="id" size="25" maxlength="30"></td> 
  10.     </tr> 
  11.     <tr> 
  12.         <td height="14">广告类型<font color="#FF0000">*</font>&nbsp; &nbsp;  
  13.         </td> 
  14.         <td height="14"><select name="nx" id="nx"> 
  15.             <option value="纯HTML">纯HTML</option> 
  16.             <option value="脚本式">脚本式</option> 
  17.         </select> HTML中的换行符将会被省略掉。</td> 
  18.     </tr> 
  19.     <tr> 
  20.         <td>规格(宽*高)</td> 
  21.         <td><input name="gge" type="TEXT" class="input" id="id" value="X" 
  22.             size="20" maxlength="30"></td> 
  23.     </tr> 
  24.     <tr> 
  25.         <td height="76" valign="top"> 
  26.         <p>广告内容<font color="#FF0000">*</font></p> 
  27.         </td> 
  28.         <td valign="middle"><textarea name="data" cols="80" rows="10" 
  29.             wrap="virtual" class="input" id="data" tabindex="2"> 
  30.             </textarea></td> 
  31.     </tr> 
  32.     <tr> 
  33.         <td height="30">简单注释:</td> 
  34.         <td height="30"><textarea name="notice" cols="80" rows="4" 
  35.             wrap="virtual" class="input" id="notice" tabindex="2"> 
  36.             </textarea></td> 
  37.     </tr> 
  38.     <tr align="center"> 
  39.         <td height="30" colspan="2"><input type="submit" name="action" 
  40.             value="提交" class="botton"> <input type="reset" value="重填" 
  41.             class="botton" name="reset"> <input type="button" 
  42.             value="返回上一页" onClick="javascript:history.back(-1);"   
  43.             class='botton'></td> 
  44.     </tr> 
  45. </table> 
  46. </div> 

【代码解读】

上述页面模板代码是一个标准的数据表单。其中,表单标签中的值传递给添加广告程序(add.php)处理,添加广告程序将表单传递过来的值,拆分处理成广告存放文件的预定义格式,并写入该文件保存。

添加广告程序(add.php)的代码具体如下:

广州网站建设
  1. <?php 
  2. /*******************************************  
  3. '文件名:add.php  
  4. '主要功能:添加广告程序  
  5. '说明:  
  6. '*******************************************/  
  7. include_once(dirname(__FILE__)."/inc/include.smarty.php");    
  8.                                                     //加载Smarty配置文件  
  9. include(dirname(__FILE__). "/inc/include.function.php");    //加载函数库文件  
  10. require(dirname(__FILE__)."/config/config.php");            //加载容配置文件  
  11. $randrand=rand(0,9999);                                         //生成随机数  
  12. if($_REQUEST['action']=="提交"){  
  13. $id=$_REQUEST[id];  
  14. $nx=$_REQUEST[nx];  
  15. $gge=$_REQUEST[gge];  
  16. $notice=$_REQUEST[notice];  
  17. $data=$_REQUEST[data];  
  18. //处理文件内容  
  19. $msgd=explode("|www_allen|",file_get_contents($dbtable));   
  20. $rows=count($msgd);    
  21. for ($i=0;$i<=$rows;$i++){  
  22. $tmp2=explode("|allen|",$msgd[$i]);                     //切割字符串  
  23. $msgn[$i]=$tmp2[0];  
  24. if(eregi("^$id$",$msgn[$i])){  
  25. $chj_nr=$msgd[$i];  
  26. }  
  27. }  
  28. if($chj_nr!=""){  
  29.     error("该广告ID已经存在,请换一个吧。");              //报错信息  
  30. }  
  31. if($data=="" or $id==""){                               //判断数据是否存在  
  32. die("ID或者内容为空!");  
  33. }  
  34. $fp=fopen("$dbtable","a+");         //打开指定文件'a+'(打开文件方式为可读写)  
  35. $all.="$id|allen|$nx|allen|$data|allen|$notice|allen|$gge|www_allen|";  
  36. @fputs($fp,$all) or die(error('写入信息时出错!'));  
  37. if($nx=="纯HTML"){  
  38.     $data=allen_thu($data);  
  39.     allen_file($data,"$addata/$id.js");  
  40.     }else{  
  41.     allen_file($data,"$addata/$id.js");  
  42.     }  
  43. isok("添加广告成功!请稍等...");  
  44. }  
  45. $smarty->display("./add.html");  
  46. ?> 

广州网站设计

在浏览器中执行下面的链接测试新增广告:
广州网站设计
  1. http://localhost/ad/add.php 

 

效果如图15.9所示。添加测试广告数据后单击"提交"按钮,提示提交成功。提示成功页面如图15.10所示。
图15.9  新增广告
图15.10  添加广告成功页面
标签:
飞机