-
Notifications
You must be signed in to change notification settings - Fork 1
/
member_photo_update.php
101 lines (96 loc) · 2.59 KB
/
member_photo_update.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
<?php
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
$link = connect();
?>
<?php
$upload['success'] = null;
if (isset($_POST['submit'])&&isset($_GET['id'])){
if(is_uploaded_file($_FILES['file']['tmp_name'])){
$arr = pathinfo($_FILES['file']['name']);
$newName=time().rand(1000,9999);
// 随机生成文件名
$newPath = "uploads/{$newName}.{$arr['extension']}";
if (move_uploaded_file($_FILES['file']['tmp_name'],$newPath)){
// 移动文件事先就要建好文件夹
$upload['success'] = 'yes';
$query = "update sfk_member set photo='{$newPath}' where id={$_GET['id']}";
execute($link,$query);
}
else{
$upload['success'] = 'no';
}
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<script src="js/jquery-1.11.3.min.js"></script>
<style type="text/css">
body {
font-size:12px;
font-family:微软雅黑;
}
h2 {
padding:0 0 10px 0;
border-bottom: 1px solid #e3e3e3;
color:#444;
}
.submit {
background-color: #3b7dc3;
color:#fff;
padding:5px 22px;
border-radius:2px;
border:0px;
cursor:pointer;
font-size:14px;
}
#main {
width:80%;
margin:0 auto;
}
</style>
<script>
$(function () {
$("#file").on("change",function () {
src = URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
//直接使用这一条语句就行
//url.creatObjectUrl转化为本地预览
// console.log(this.files[0]);
$("img").attr("src",src);
})
})
</script>
</head>
<body>
<div id="main">
<h2>更改头像</h2>
<div>
<h3>原头像:</h3>
<img width="120" height="120" src="">
</div>
<div style="margin:15px 0 0 0;">
<form method="post" action="" enctype="multipart/form-data" >
<!-- 注意要添加上面enctype,表示要上传文件,不加files超全局变量为空值-->
<input style="cursor:pointer;" width="100" type="file" name="file" id="file" value=""/><br /><br />
<input class="submit" type="submit" value="submit" name="submit"/>
</form>
<p><?php
if (isset($_POST['submit'])){
if ($upload['success']=='yes'){
echo "上传成功";
}
else{
echo "上传失败";
}
}
?></p>
</div>
</div>
</body>
</html>