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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
<!doctype html>
<?php ob_start(); session_start(); error_reporting(0); ?> <?php $target_dir = "139/"; $passwordLogin = "Xx1658df"; ?> <html>
<head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token --> <meta name="csrf-token" content="{{ csrf_token() }}"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <title>uploadFile</title> </head>
<body> <div class="container"> <?php if($_SESSION['valid']!=true){ echo '<form method="post" enctype="multipart/form-data"> <input type="password" name="password" id="password" placeholder="password" required> <button class="btn btn-success" type="submit" name="pass"> Login </button> </form>'; } ?> <?php if($_SESSION['valid']==true){ echo '<form method="post" enctype="multipart/form-data"> <button class="btn btn-success" type="submit" name="logout"> Logout </button> </form>'; } ?>
<!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">เพิ่มไฟล์</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div>
<div class="form-group row"> <form method="post" enctype="multipart/form-data"> <div class="modal-body"> <div class="col-sm-12 text-center"> <div class="form-group row"> <label for="name_file" class="col-md-3 col-form-label text-md-right"> ชื่อไฟล์ : </label> <input type="file" name="fileToUpload" value="Upload Html" id="file" class="col-md-6 file-upload-default pt-2" placeholder="File" required> </div> </div> </div>
<div class="modal-footer"> <button class="btn btn-secondary" type="button" data-bs-dismiss="modal"> ยกเลิก </button> <button class="btn btn-success" type="submit" name="submit"> บันทึก </button> </div> </div> </form>
</div> </div> </div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js" integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous"></script> </body>
</html>
<?php
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image if(isset($_POST["submit"])) { $uploadOk = 1; }
if(isset($_POST["logout"])) { session_start(); unset($_SESSION['valid']); echo "<meta http-equiv='refresh' content='0'>"; }
if(isset($_POST["pass"])) { if($_POST["password"]== $passwordLogin){
$_SESSION['valid']= true; $_SESSION['timeout']= time(); echo "<meta http-equiv='refresh' content='0'>"; } }
if($_SESSION['valid']==true){ echo ' <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">uploadFile</h6> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">เพิ่ม</button>
</div> <div class="card-body"> <div class="table-responsive"> <table class="table table-hover table-responsive-sm" id="dataTable" width="100%" cellspacing="0"> <thead class="thead-primary"> <tr> <th>ลำดับ</th> <th>FILE NAME</th> <th>จัดการ</th> </tr> </thead> <tbody>
' .$i; $fileList = glob($target_dir . "*"); foreach($fileList as $filename){ $i++; if(is_file($filename)){ echo "<tr>"; echo "<td> $i </td>"; echo "<td> $filename </td>"; echo '<td><form method="post"> <button type="submit" class="btn btn-danger" name="delete">ลบ</button></form></td>'; } } ' </tbody> </table> </div> </div> </div> '; }
if(isset($_POST["delete"])) { unlink("$filename"); echo "<meta http-equiv='refresh' content='0'>"; }
// Check if file already exists if (!file_exists($target_dir)) { mkdir($target_dir); }
if (file_exists($target_file)) { $temp = explode(".", $_FILES["fileToUpload"]["name"]); $newfilename = round(microtime(true)) . '.' . end($temp); if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir . $newfilename )){ echo "The file " .$newfilename. " has been uploaded."; echo "<meta http-equiv='refresh' content='0'>"; }else{ echo ""; } }
// Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; }
// Allow certain file formats if($imageFileType != "html" ) { echo ""; $uploadOk = 0; }
// Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo ""; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "<meta http-equiv='refresh' content='0'>"; } else { echo ""; } }
?>
|