自己写的一个简单的网盘demo

曾经终败给现在 2022-01-16 00:17 352阅读 0赞

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

index.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>登录页</title>
  6. </head>
  7. <body>
  8. <h1>Login:</h1>
  9. <form action="checkuser.php" method="post">
  10. 用户名:<input type="text" name="username" /><br />
  11. 密码:<input type="password" name="password" /><br />
  12. <input type="submit" name="sub" value="登录" />
  13. <a href="register.php">unregister yet? click me to register</a>
  14. </form>
  15. </body>
  16. </html>

register.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>注册页</title>
  6. </head>
  7. <body>
  8. <h1>Register:</h1>
  9. <form action="add2db.php" method="post">
  10. 用户名:<input type="text" name="username" /><br />
  11. 密码:<input type="password" name="password" /><br />
  12. <input type="submit" name="sub" value="提交" />
  13. </form>
  14. </body>
  15. </html>

add2db.php:

  1. <?php
  2. $con = mysql_connect("localhost","root","*******");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. mysql_select_db("wangpan", $con);
  8. $sql = "insert into users (username, password)
  9. values ('".$_POST['username']."', '".$_POST['password']."')";
  10. mysql_query($sql);
  11. echo "<script>alert('注册成功,前往登录!');
  12. location.href='http://1.1.1.1/wangpan/index.php';</script>";
  13. ?>

checkuser.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>checkuser</title>
  6. </head>
  7. <body>
  8. <?php
  9. $con = mysql_connect("localhost","root","*******");
  10. if (!$con)
  11. {
  12. die('Could not connect: ' . mysql_error());
  13. }
  14. mysql_select_db("wangpan", $con);
  15. $sql = "select * from users
  16. where username='".$_POST['username']."' limit 1";
  17. $result = mysql_query($sql);
  18. if ($result) {
  19. $userinfo = mysql_fetch_array($result);
  20. if ($_POST['username']===$userinfo['username']
  21. && $_POST['password']===$userinfo['password']) {
  22. $_SESSION['userid'] = $userinfo['user_id'];
  23. $_SESSION['username'] = $userinfo['username'];
  24. echo "<script>alert('登录成功!');
  25. location.href='http://1.1.1.1/wangpan/indexpage.php';</script>";
  26. }
  27. }else {
  28. echo "用户名不存在!";
  29. }
  30. ?>
  31. </body>
  32. </html>

indexpage.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>首页</title>
  6. </head>
  7. <body>
  8. <h1>Welcome back! <?php echo $_SESSION['username']; ?></h1>
  9. <hr />
  10. <form action="upload.php" method="post" enctype="multipart/form-data">
  11. <input type="file" name="file" />
  12. <input type="submit" name="sub" />
  13. </form>
  14. <hr />
  15. <h2>File list of you:</h2>
  16. <?php
  17. require_once 'getfile.php';
  18. ?>
  19. </body>
  20. </html>

upload.php:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>upload</title>
  6. </head>
  7. <body>
  8. <?php
  9. if (1)
  10. {
  11. if ($_FILES["file"]["error"] > 0)
  12. {
  13. echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  14. }
  15. else
  16. {
  17. echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  18. echo "Type: " . $_FILES["file"]["type"] . "<br />";
  19. echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  20. echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
  21. session_start();
  22. echo $_SESSION['username'];
  23. if (file_exists("upload/" . $_FILES["file"]["name"]))
  24. {
  25. echo $_FILES["file"]["name"] . " already exists. ";
  26. }
  27. else
  28. {
  29. $location = $_SESSION['username']."/";
  30. if (is_dir($location)){
  31. move_uploaded_file($_FILES["file"]["tmp_name"],
  32. $location . $_FILES["file"]["name"]);
  33. }else {
  34. mkdir($location);
  35. move_uploaded_file($_FILES["file"]["tmp_name"],
  36. $location . $_FILES["file"]["name"]);
  37. }
  38. }
  39. }
  40. }
  41. else
  42. {
  43. echo "Invalid file";
  44. }
  45. ?>
  46. </body>
  47. </html>

getfile.php:

  1. <?php
  2. $filelist = scandir($_SESSION['username']);
  3. foreach ($filelist as $filename){
  4. if ($filename!='.' && $filename!='..'){
  5. ?>
  6. <a href="http://1.1.1.1/wangpan/<?php echo $_SESSION['username'];?>/<?php echo $filename;?>"><?php echo $filename;?></a><br />
  7. <?php
  8. }
  9. }
  10. ?>

一个简易的微型网盘,我在用手机端测试的时候惊奇的发现手机端的浏览器会将input标签识别为3部分:相机、图片和文件,挺好的。还有考虑到手机端的情况,我建议不要用alert了,不像pc端直接弹一句话,它还会额外的多弹出一句看着很二的话。

转载于:https://my.oschina.net/ITHaozi/blog/132037

发表评论

表情:
评论列表 (有 0 条评论,352人围观)

还没有评论,来说两句吧...

相关阅读