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
83 lines (66 loc) · 1.92 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
<?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:500px;
margin:20px auto;
}
td{
padding:5px 10px;
}
td img{
width:120px;
}
</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=$_FILES['filename']['name'];
$filename=time() . $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'],"./files/".$filename);
$desc=$_POST['desc'];
insert("imgs",['filename'=>$filename,'desc'=>$desc]);
}else{
echo "上傳失敗,請檢查檔案格式或是大小是否符合規定";
}
}
?>
<!----透過檔案讀取來顯示檔案的資訊,並可對檔案執行更新或刪除的工作----->
<?php
$rows=all('imgs');
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><a href='re_upload.php?id={$file['id']}'>編輯資料</a></td>";
echo "</tr>";
}
echo "</table>";
?>
<!----透過資料表來顯示檔案的資訊,並可對檔案執行更新或刪除的工作----->
</body>
</html>