-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntitled-2.php
executable file
·59 lines (48 loc) · 1.53 KB
/
Untitled-2.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文件</title>
</head>
<?php
//取得上傳檔案資訊
$filename=$_FILES['image']['name'];
$tmpname=$_FILES['image']['tmp_name'];
$filetype=$_FILES['image']['type'];
$filesize=$_FILES['image']['size'];
$file=NULL;
if(isset($_FILES['image']['error'])){
if($_FILES['image']['error']==0){
$instr = fopen($tmpname,"rb" );
$file = addslashes(fread($instr,filesize($tmpname)));
}
}
//新增圖片到資料庫
$conn=mysql_pconnect("localhost","bernie","1111");
mysql_select_db("db");
mysql_query("SET NAMES'utf8'");
$sql=sprintf("insert into imageDB(image)values(%s)","'".$file."'");
mysql_query($sql);
mysql_close($conn);
?>
<?php
//從資料庫取得圖片
$conn=mysql_pconnect("localhost","bernie","1111");
mysql_select_db("db");
mysql_query("SET NAMES'utf8'");
$sql=sprintf("select * from imageDB where id=1");
$result=mysql_query($sql);
//顯示圖片
if($row=mysql_fetch_assoc($result)){
header("Content-type: image/jpeg");
print $row['image'];
}
mysql_close($conn);
?>
<body>
<form enctype="multipart/form-data" method="post" action="upload.php">
<input type="file" name="image" />
<input type="submit" value="確定上傳"/>
</form>
</body>
</html>