当前位置:首页 > PHP教程 > php上传下载 > 列表

php需登录的文件上传管理系统

发布:smiling 来源: PHP粉丝网  添加日期:2021-06-21 11:08:32 浏览: 评论:0 

这篇文章主要介绍了php需登录的文件上传管理系统,文章中跟大家分享了一个很完整的php代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

本文给大家介绍一个不错的需要登录的php 文件上传管理系统,功能简单有需要了解的同学可参考。

代码如下:

  1. <?php 
  2. $admin_pw="admin";//管理密码 
  3. $uploaddir="upload";//上传目录 
  4. session_start(); 
  5. if($_GET['action']=="getcode") 
  6. { 
  7.  setcode(); 
  8.  exit(); 
  9. } 
  10. if($_POST['password']==$admin_pw && $_POST['yz']==$_SESSION['yzcode']) 
  11. { 
  12.  $_SESSION['logined']=$admin_pw; 
  13. } 
  14. if($_GET['action']=="logout") 
  15. { 
  16.  $_SESSION['logined']=""; 
  17.  header("location: ".$_SERVER['PHP_SELF']); 
  18.  exit(); 
  19. } 
  20. if($_SESSION['logined']!=$admin_pw) 
  21. { 
  22. ?> 
  23. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  24. <html xmlns="http://www.w3.org/1999/xhtml"> 
  25. <head> 
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  27. <title>请登录</title> 
  28. </head> 
  29. <body> 
  30. <form action="" method="post"> 
  31. 输入密码:<input type="password" name="password" style="width:100px;" /><br />验证字符:<input type="text" style="width:40px;" name="yz" /><a href="#" onclick="document.tzm.src='?action=getcode';"><img src="?action=getcode" alt="验证码" id="tzm" name="tzm" /></a><br /><input type="submit" value="进入管理" /> 
  32. </form> 
  33. </body> 
  34. </html> 
  35. <?php 
  36. } 
  37. else 
  38. { 
  39. ?> 
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  41. <html xmlns="http://www.w3.org/1999/xhtml"> 
  42. <head> 
  43. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  44. <title>文件上传</title> 
  45. </head> 
  46. <body> 
  47. <?php 
  48.  if($_POST['ac']=="upload") 
  49.  { 
  50.  $fileall=explode('.',$_FILES['file']['name']); 
  51.  $filetype=$fileall[count($fileall)-1]; 
  52.  $filename=$uploaddir."/".$_FILES['file']['name']."_".rand(1,999999999).".".$filetype; 
  53.  $fileexists=file_exists($filename); 
  54.  while($fileexists==true) 
  55.  { 
  56.  $filename=$uploaddir."/".$_FILES['file']['name']."_".rand(1,999999999).".".$filetype; 
  57.  $fileexists=file_exists($filename); 
  58.  } 
  59.  if(move_uploaded_file($_FILES["file"]["tmp_name"],$filename)) 
  60.  { 
  61.  $url="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];  
  62.  echo "文件:".$filename." 上传成功!<br>文件地址:<input type=text style='width:350px;' value=".dirname($url)."/".$filename." /><a href=".dirname($url)."/".$filename." target="_blank">测试</a>"; 
  63.  } 
  64.  else 
  65.  { 
  66.  echo "文件".$filename."上传失败!"; 
  67.  } 
  68.  } 
  69. ?> 
  70. <form action="" method="post" enctype="multipart/form-data"> 
  71. 选择文件:<input type="file" name="file" id="file" width="100px" /><input type="hidden" name="ac" value="upload" /><input type="submit" value="上传" /> 
  72. </form> 
  73. <p><a href="?action=logout">退出登录</a></p> 
  74. </body> 
  75. </html> 
  76. <?php 
  77. } 
  78.  
  79. function setcode() 
  80. { 
  81.  Header("Content-type: image/gif"); 
  82.  $border = 0; //是否要边框 1要:0不要 
  83.  $how = 4; //验证码位数 
  84.  $w = $how*15; //图片宽度 
  85.  $h = 20; //图片高度 
  86.  $fontsize = 5; //字体大小 
  87.  $alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母 
  88.  $number = "0123456789"; //验证码内容2:数字 
  89.  $randcode = ""; //验证码字符串初始化 
  90.  srand((double)microtime()*1000000); //初始化随机数种子 
  91.  $im = ImageCreate($w, $h); //创建验证图片 
  92.  $bgcolor = ImageColorAllocate($im, 255, 255, 255); //设置背景颜色 
  93.  ImageFill($im, 0, 0, $bgcolor); //填充背景色 
  94.  if($border) 
  95.  { 
  96.  $black = ImageColorAllocate($im, 0, 0, 0); //设置边框颜色 
  97.  ImageRectangle($im, 0, 0, $w-1, $h-1, $black);//绘制边框 
  98.  } 
  99.  for($i=0; $i<$how; $i++) 
  100.  {  
  101.  $alpha_or_number = mt_rand(0, 1); //字母还是数字 
  102.  $str = $alpha_or_number ? $alpha : $number; 
  103.  $which = mt_rand(0, strlen($str)-1); //取哪个字符 
  104.  $code = substr($str, $which, 1); //取字符 
  105.  $j = !$i ? 4 : $j+15; //绘字符位置 
  106.  $color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); //字符随即颜色 
  107.  ImageChar($im, $fontsize, $j, 3, $code, $color3); //绘字符 
  108.  $randcode .= $code; //逐位加入验证码字符串 
  109.  } 
  110.  $_SESSION['yzcode'] = $randcode; 
  111.  Imagegif($im); 
  112.  ImageDestroy($im); 
  113. } 
  114. ?>

Tags: php文件上传管理系统

分享到: