forked from wdaweb/113php-2-11304-PHP_FILE_AND_GRAPHIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.php
125 lines (93 loc) · 2.66 KB
/
manage.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
<?php
/**
* 1.建立資料庫及資料表來儲存檔案資訊
* 2.建立上傳表單頁面
* 3.取得檔案資訊並寫入資料表
* 4.製作檔案管理功能頁面
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>檔案管理功能</title>
<link rel="stylesheet" href="style.css">
<style>
table {
width: 700px;
margin: 20px auto;
}
td {
padding: 5px 10px;
}
td img {
width: 120px;
}
.continue {
width: 100px;
height: 22px;
margin:auto;
text-align: center;
background-color: lightblue;
}
a {
display: inline-block;
padding: 5px 10px;
border: 1px solid #ccc;
margin: 5px;
border-radius: 8px;
}
a:hover {
background-color: skyblue;
}
</style>
</head>
<body>
<h1 class="header">檔案管理練習</h1>
<!----建立上傳檔案表單及相關的檔案資訊存入資料表機制----->
<?php
include_once "function.php";
// 印出陣列,檢查用
// echo $_POST['name'];
// echo "<br>";
// dd($_FILES);
if(isset($_FILES['filename'])){
if($_FILES['filename']['error']==0){
$filename=time() . $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'],"./files/".$filename);
$desc=$_POST['desc'];
save("imgs",['filename'=>$filename,'desc'=>$desc]);
}else{
echo "上傳失敗,請檢查檔案格式或大小是否符合規定";
}
}
?>
<!----透過檔案讀取來顯示檔案的資訊,並可對檔案執行更新或刪除的工作----->
<?php
$rows=all('imgs');
// $dirpath="./files";
// $dir=opendir($dirpath);
// $items=scandir($dirpath);
// $items=array_diff($items,array('.','..'));
echo "<table>";
foreach($rows as $file){
echo "<tr>";
echo "<td><img src='files/{$file['filename']}'></td>";
echo "<td>{$file['desc']}<td>";
echo "<td><a href='del_img.php?id={$file['id']}'>刪除</a></td>";
echo "<td>";
echo "<a href='show_img.php?id={$file['id']}'>";
echo ($file['sh']==1)?"隱藏":"顯示";
echo "</a>";
echo "<a href='re_upload.php?id={$file['id']}'>重新上傳</a></td>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
<div class="continue"><a href="upload.php">繼續新增</a></div>
<!----透過資料表來顯示檔案的資訊,並可對檔案執行更新或刪除的工作----->
</body>
</html>