我的 WAP 上传通道

0

Comments

这年头……手机连接线也要大几十块……我穷人买不起……于是就想利用我的空间建一个 WAP 上传通道,记得上一次放了一个下载通道。这样我要让手机和电脑互传就没有障碍了!

去网上找了一下,很短的时间写了个小程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// 前面就是 xhtml 的需要了
header("Content-Type: application/xhtml+xml");
echo "<?xml version='1.0' encoding='utf-8'?>";
?>
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml;charset=UTF-8" />
<title>WAP上传通道</title>
</head>
<body>
<?php
if ($_FILES['file'])
{
	// 验证密码,不想让谁都能随便上传……
	if (md5($_POST['password']) != '********************************') {
		echo "密码错误!";
	}
	else {
		define('UPLOAD_DIR', dirname(__FILE__) . '/upload');
		@mkdir(UPLOAD_DIR);
		if (move_uploaded_file($_FILES['file']['tmp_name'], 
			UPLOAD_DIR . '/' . basename($_FILES['file']['name']))) {
			echo basename($_FILES['file']['name']) . 
				" ({$_FILES['file']['size']}bytes) 上传成功!";
		} else {
			echo "上传失败!({$_FILES['file']['error']})<br />";
			switch ($_FILES['file']['error']) {
				case UPLOAD_ERR_INI_SIZE:
				case UPLOAD_ERR_FORM_SIZE:
					echo "大小超过限制的值"; break;
				case UPLOAD_ERR_PARTIAL:
				case UPLOAD_ERR_NO_FILE:
					echo "上传文件不完整"; break;
				case UPLOAD_ERR_NO_TMP_DIR:
				case UPLOAD_ERR_CANT_WRITE:
					echo "其他错误"; break;
			}
		}
	}
}
echo "<br />";
?>
<form name="upload" method="post" action="index.php" enctype="multipart/form-data">
上传密码:<input type="password" name="password" /><br />
<input type="file" name="file" /><br />
<input type="submit" value="提交" />
</form>
</body> 
</html>

马上试验了一下,就成功了!

很好很强大!拿来分享一下~

Leave a Reply