-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
48 lines (46 loc) · 1.51 KB
/
index.php
File metadata and controls
48 lines (46 loc) · 1.51 KB
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
<?php require 'config.php';
?>
<!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>Document</title>
</head>
<body>
<?php
$dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
if (isset($_POST['btn'])) {
$tag = strip_tags($_POST['tag']);
foreach ($_FILES['myfile']['tmp_name'] as $key => $val) {
$name = $_FILES['myfile']['name'][$key];
$type = $_FILES['myfile']['type'][$key];
$data = file_get_contents($_FILES['myfile']['tmp_name'][$key]);
$stmt = $dbh->prepare('INSERT INTO myblob(name,mime,data,tag) VALUES(:name,:type,:data,:tag)');
$stmt->bindParam(':name', $name);
$stmt->bindParam(':type', $type);
$stmt->bindParam(':data', $data);
$stmt->bindParam(':tag', $tag);
$stmt->execute();
}
}
?>
<form method="post" enctype="multipart/form-data" >
<input type="text" name="tag" id="tag">
<input type="file" name="myfile[]" multiple="multiple">
<button name="btn">Upload</button>
</form>
<p></p>
<ol>
<?php
$stat = $dbh->prepare('SELECT * from myblob');
$stat->execute();
while ($row = $stat->fetch()) {
echo '<li><a target="_blank" href="view.php?id=' . $row['id'] . '">' . $row['name'] . '</a><br>
<embed src="data:' . $row['mime'] . ';base64,' . base64_encode($row['data']) . '" width="200"></li>';
}
?>
</ol>
</body>
</html>