自己写的一个简单的网盘demo
2019独角兽企业重金招聘Python工程师标准>>>
index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登录页</title>
</head>
<body>
<h1>Login:</h1>
<form action="checkuser.php" method="post">
用户名:<input type="text" name="username" /><br />
密码:<input type="password" name="password" /><br />
<input type="submit" name="sub" value="登录" />
<a href="register.php">unregister yet? click me to register</a>
</form>
</body>
</html>
register.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册页</title>
</head>
<body>
<h1>Register:</h1>
<form action="add2db.php" method="post">
用户名:<input type="text" name="username" /><br />
密码:<input type="password" name="password" /><br />
<input type="submit" name="sub" value="提交" />
</form>
</body>
</html>
add2db.php:
<?php
$con = mysql_connect("localhost","root","*******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("wangpan", $con);
$sql = "insert into users (username, password)
values ('".$_POST['username']."', '".$_POST['password']."')";
mysql_query($sql);
echo "<script>alert('注册成功,前往登录!');
location.href='http://1.1.1.1/wangpan/index.php';</script>";
?>
checkuser.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checkuser</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","*******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("wangpan", $con);
$sql = "select * from users
where username='".$_POST['username']."' limit 1";
$result = mysql_query($sql);
if ($result) {
$userinfo = mysql_fetch_array($result);
if ($_POST['username']===$userinfo['username']
&& $_POST['password']===$userinfo['password']) {
$_SESSION['userid'] = $userinfo['user_id'];
$_SESSION['username'] = $userinfo['username'];
echo "<script>alert('登录成功!');
location.href='http://1.1.1.1/wangpan/indexpage.php';</script>";
}
}else {
echo "用户名不存在!";
}
?>
</body>
</html>
indexpage.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>首页</title>
</head>
<body>
<h1>Welcome back! <?php echo $_SESSION['username']; ?></h1>
<hr />
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="sub" />
</form>
<hr />
<h2>File list of you:</h2>
<?php
require_once 'getfile.php';
?>
</body>
</html>
upload.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload</title>
</head>
<body>
<?php
if (1)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
session_start();
echo $_SESSION['username'];
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
$location = $_SESSION['username']."/";
if (is_dir($location)){
move_uploaded_file($_FILES["file"]["tmp_name"],
$location . $_FILES["file"]["name"]);
}else {
mkdir($location);
move_uploaded_file($_FILES["file"]["tmp_name"],
$location . $_FILES["file"]["name"]);
}
}
}
}
else
{
echo "Invalid file";
}
?>
</body>
</html>
getfile.php:
<?php
$filelist = scandir($_SESSION['username']);
foreach ($filelist as $filename){
if ($filename!='.' && $filename!='..'){
?>
<a href="http://1.1.1.1/wangpan/<?php echo $_SESSION['username'];?>/<?php echo $filename;?>"><?php echo $filename;?></a><br />
<?php
}
}
?>
一个简易的微型网盘,我在用手机端测试的时候惊奇的发现手机端的浏览器会将input标签识别为3部分:相机、图片和文件,挺好的。还有考虑到手机端的情况,我建议不要用alert了,不像pc端直接弹一句话,它还会额外的多弹出一句看着很二的话。
转载于//my.oschina.net/ITHaozi/blog/132037
还没有评论,来说两句吧...