-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntitled-1.php
executable file
·126 lines (120 loc) · 5.24 KB
/
Untitled-1.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
header("charset=utf-8");
//取得目前路徑
$fileDir = "./uplode/";
//執行刪除動作
if(isset($_GET["action"])&&$_GET["action"]=="delete"){
$_GET["file"] = iconv("utf-8", "big5", $_GET["file"]);
unlink($_GET["file"]);
$fileDir =pathinfo($_GET["file"],PATHINFO_DIRNAME);
//重新轉頁到目前目錄中
header("Location: ?dir=".$fileDir);
}
//執行上傳動作
if(isset($_GET["action"])&&$_GET["action"]=="upload"){
if($_FILES["upload"]["error"]==0){
//$fileName = iconv('utf-8','big5', $_FILES["upload"]["name"]);
move_uploaded_file($_FILES["upload"]["tmp_name"], iconv("utf-8","big5", $_POST["dir"]."//".$_FILES["upload"]["name"]));
}
//重新轉頁到目前目錄中
header("Location: ?dir=".$_POST["dir"]);
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>檔案管理</title>
</head>
<body>
<?php
//若有URL參數dir,其值即為目前路徑
if(isset($_GET["dir"])&&$_GET["dir"]!=""){
$fileDir = $_GET["dir"];
}
//目前路徑上一層路徑
$fileUplevel = dirname($fileDir);
//取得目前路徑中的內容
$fileResource = scandir($fileDir);
echo '<table width="500" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000000">';
//顯示目前路徑
echo '<tr><td bgcolor="#FAFAFA"colspan="3">目前路徑:'.$fileDir.'</td></tr>';
echo '<tr><td bgcolor="#FAFAFA"colspan="3" align="center">';
//設定URL參數action為upload
echo '<form action="?action=upload" method="post" enctype="multipart/form-data" name="form1" id="form1">';
//將上一層路徑帶進連結的URL參數dir中
echo '上傳檔案 <input type="file" name="upload" style="height:20px" />';
echo '<input type="submit" name="button" style="height:20px" value="送出" />';
echo '<input name="dir" type="hidden" id="dir" value="'.$fileDir.'" /></form>';
echo '<tr><td bgcolor="#FAFAFA">名稱</td><td bgcolor="#FAFAFA" width="120" align="center">檔案大小</td><td bgcolor="#FAFAFA" width="80" align="center">功能</td></tr>';
//顯示資料夾內容
foreach($fileResource as $fileName){
if(is_dir($fileDir.'\\'.$fileName)){
//不顯示相對路徑「.」及「..」
if($fileName != "." && $fileName !=".."){
//顯示資料夾,並設定該資料夾的路徑帶進連結的URL參數dir中
echo '<tr><td bgcolor="#FAFAFA" width="300"><a href="?dir='.$fileDir.'//'.$fileName.'"><'.$fileName.'></a></td>';
echo '<td bgcolor="#FAFAFA" width="120"> </td><td bgcolor="#FAFAFA" width="80"> </td></tr>';
}
}
}
//顯示檔案的內容
foreach($fileResource as $fileName){
if(is_file($fileDir.'\\'.$fileName)){
//計算檔案大小
$fsize = filesize($fileDir.'\\'.$fileName);
//顯示檔案名稱
$fileName=iconv("BIG5", "UTF-8",$fileName);
echo '<tr><td bgcolor="#FAFAFA" width="300">'.$fileName.'</td>';
//顯示檔案大小,並以千位符號格式化顯示
echo '<td bgcolor="#FAFAFA" width="120" align="right">'.number_format($fsize).' bytes</td>';
//在刪除文字上加上連結,並設定該資料夾的路徑帶進連結的URL參數dir、參數action為delete
echo '<td bgcolor="#FAFAFA" width="80" align="center"><a href="?file='.$fileDir.'\\'.$fileName.'&action=delete">刪除</a></td></tr>';
}
}
echo '</table>';
?>
<div style="margin-top:100px;">
<?php
//若有URL參數dir,其值即為目前路徑
if(isset($_GET["dir"])&&$_GET["dir"]!=""){
$fileDir = $_GET["dir"];
}
//目前路徑上一層路徑
$fileUplevel = dirname($fileDir);
//取得目前路徑中的內容
$fileResource = scandir($fileDir);
echo '<table width="500" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#000000">';
//顯示目前路徑
echo '<tr><td bgcolor="#FAFAFA"colspan="3">目前路徑:'.$fileDir.'</td></tr>';
echo '<tr><td bgcolor="#FAFAFA"colspan="3" align="center">';
//設定URL參數action為upload
echo '<tr><td bgcolor="#FAFAFA">名稱</td><td bgcolor="#FAFAFA" width="120" align="center">檔案大小</td><td bgcolor="#FAFAFA" width="80" align="center">功能</td></tr>';
//顯示資料夾內容
foreach($fileResource as $fileName){
if(is_dir($fileDir.'\\'.$fileName)){
//不顯示相對路徑「.」及「..」
if($fileName != "." && $fileName !=".."){
//顯示資料夾,並設定該資料夾的路徑帶進連結的URL參數dir中
echo '<tr><td bgcolor="#FAFAFA" width="300"><a href="?dir='.$fileDir.'//'.$fileName.'"><'.$fileName.'></a></td>';
echo '<td bgcolor="#FAFAFA" width="120"> </td><td bgcolor="#FAFAFA" width="80"> </td></tr>';
}
}
}
//顯示檔案的內容
foreach($fileResource as $fileName){
if(is_file($fileDir.'\\'.$fileName)){
//計算檔案大小
$fsize = filesize($fileDir.'\\'.$fileName);
//顯示檔案名稱
$fileName=iconv("BIG5", "UTF-8",$fileName);
echo '<tr><td bgcolor="#FAFAFA" width="300">'.$fileName.'</td>';
//顯示檔案大小,並以千位符號格式化顯示
echo '<td bgcolor="#FAFAFA" width="120" align="right">'.number_format($fsize).' bytes</td>';
//在刪除文字上加上連結,並設定該資料夾的路徑帶進連結的URL參數dir、參數action為下載
echo '<td bgcolor="#FAFAFA" width="80" align="center"><a href="po/'.$fileName.'" target="1_blank">下載</a></td></tr>';
}
}
echo '</table>';
?>
</div>
</body>
</html> - See more at: http://roberchen3.blogspot.tw/2014/11/blog-post.html#sthash.pn1CuQgY.dpuf