不用数据库的多用户文件自由上传投票系统(1)

  这是我近来开发的一套上传投票一体化的系统,共由4个php和若干记录文件组成,这是第一个view.php,主要负责显示文件列表和上传的文件表单和文件名的检验.其中的地址均为真实地址,请使用时作相应修改,我将在最后1篇提供具体的使用方法。

  <html>

  <head>

  <link rel="stylesheet" href="../css/eccct.css">

  </head>

  <body>

  <center>

  <script src=http://home.classover.com/~vampirehunter/js/menu.js></script>

  <script>

  function opennewwin(url){

  window.open(url,null,"height=200,width=200,status=no,toolbar=no,menubar=no,location=no");

  }

  function check(theform){

  var tempstr=theform.upfile.value.split("\");

  var files=tempstr[tempstr.length-1].split(".");

  if(theform.writer.value=="" || theform.upfile.value=="" ){alert("作者与文件名不能为空");event.returnValue= false; }

  if(escape(tempstr[tempstr.length-1]).indexOf("%u")!=-1){

  alert("文件名不能为中文");

  event.returnValue= false;

  }

  if(files.length<2 || (files[1]!="rar" && files[1]!="zip")){

  alert("文件名必须以小写zip或rar结尾");

  event.returnValue= false;

  }

  }

  </script>

  </head>

  <body>

  <?php

  //col为栏目,当存在$uploadto/$col.if(纪录title),$col.ip,$col.ipd,$col.lst时合法

  //

  //page为第几页1-n

  //rowperpage为每页几行

  if(!$page) $page=0;

  $rowperpage=5;

  if(!$col) die("系统出错");

  $cgiroot="http://eccct.51.net/cgi-bin/";//此php所在位置

  $uploadto="../uploadfile/".$col."/";

  $fp=@fopen($uploadto.$col.".if","r") or die("系统出错");

  $title=fread($fp,filesize($uploadto.$col.".if"));

  fclose($fp);//$title为本上传的名称

  $recfile=$uploadto.$col.".lst";

  $fp=@fopen($recfile,"r") or die("系统出错");

  $info=explode(">",fread($fp,filesize($recfile)));

  fclose($fp);

  $maxpage=ceil((sizeof($info)-1)/$rowperpage);

  if(!$maxpage) $maxpage=1;

  if($page>$maxpage||$page<1)$page=1;

  echo "<table class=tb cellspacing=0 cellpadding=0 ><tr><td colspan=10><br><br><center><h2>".$title."<hr></h2></center></td></tr><tr>";

  echo "<td width=25%>共".(sizeof($info)-1)."个作品</td>";

  echo "<td width=25%>第".$page."/".$maxpage."页</td>";

  echo "<td width=25%>";

  if($page+1<=$maxpage)

  echo "<a href='view.php?col=".$col."&page=".($page+1)."'>下一页</a>";

  echo "</td>";

  echo "<td width=25%>";

  if($page-1>0)

  echo "<a href='view.php?col=".$col."&page=".($page-1)."'>上一页</a>";

  echo "</td>";

  echo "</tr></table><br><br>";

  $startrec=($page-1)*$rowperpage;

  $endrec=$startrec+$rowperpage;

  for($i=$startrec;$i<$endrec&&$info[$i]!="";$i++){

  $items=explode("<",$info[$i]);

  if(!trim($items[0])) continue;

  echo "<table class='tb' border=1 cellspacing=0 cellpadding=0>";

  echo "<tr><td width=16.5% class=items>编号</td>";

  echo "<td width=16.5%  class=values>".$items[0]."</td>";

  if(!trim($items[1]))$items[1]="打死我也不说";

  echo "<td width=16.5%  class=items>作者</td><td width=16.5% class=values>".$items[1]."</td>";

  $temp=sprintf("%d",trim($items[5])/1024);

  echo "<td width=16.5% class=items>文件名</td><td class=values>".trim($items[2])."(".$temp."KB)</td>";

  echo "</tr><tr>";

  echo "<td  class=items>得票数</td><td class=values >".$items[3]."</td>";

  echo "<td class=items>下载次数</td><td class=values width=13%>".$items[6]."</td>";

  $click="opennewwin("download.php?num=".$items[0]."&col=".$col."");return false;";

  $ev="<td class=values><input type='button' value=下载 onclick='".$click."'></td>";

  echo $ev;

  echo "<td  class=values><a href='vote2.php?col=".$col."&option=".$items[0]."' >我要投票</a></td></tr>";

  if(!trim($items[4]))$items[4]="保密";

  echo "<tr><td class=items>简介</td><td class=values colspan=10>".$items[4]."</td></tr>";

  echo "</table><br><br>";

  }

  ?>

  <form method="post" action="upload.php" enctype="multipart/form-data" onsubmit="check(this);">

  <table class=tb border=1>

  <tr><td><center><h2>我要投稿</h2></center></td></tr>

  <tr><td>

  作者:<input type="text" name="writer"></td></tr>

  <tr><td>简介:<TEXTAREA name="intro" STYLE="width:600;overflow:hidden" >

  </TEXTAREA>

  </td></tr>

  <tr><td> <input type=hidden name=col value="<? echo $col?>">

  文件:<input type="file" name="upfile">(文件名请不要包含中文,文件小于1MB,以zip,rar结尾)</td></tr>

  <tr><td align="center">  <input type="submit" name="Submit" value="提交">

  </td></tr>

  </table>

  </form>

  </center>

  </body>

  </html>