-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg_select.php
199 lines (184 loc) · 5.3 KB
/
img_select.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
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
<!DOCTYPE HTML>
<html>
<meta name="renderer" content="webkit">
<meta charset="UTF-8">
<title>经验共享平台</title>
<link rel="bookmark" type="image/x-icon" href="img/+1.ico" />
<link rel="shortcut icon" href="img/+1.ico">
<link rel="icon" href="img/+1.ico">
<link rel="stylesheet" href="style/css/bootstrap.css">
<script src="style/js/jquery.js"></script>
<script src="style/js/bootstrap.js"></script>
<script src="style/js/jquery.cropit.js"></script>
<!--notify-->
<link rel="stylesheet" href="style/css/animate.css">
<script src="style/js/bootstrap-notify.js"></script>
<?php
include("common.php");
if (isset($_GET['type'])) $type = $_GET['type'];
else header("Refresh: 1; url=404.php");
if ($type == 'passage' and isset($_GET['pid']))
{?>
<style>
.cropit-preview {
background-color: #f8f8f8;
background-size: cover;
border: 1px solid #ccc;
border-radius: 3px;
margin-top: 7px;
width: 300px;
height: 150px;
}
.cropit-preview-background {
opacity: .2;
}
input.cropit-image-zoom-input {
position: relative;
}
#image-cropper {
overflow: hidden;
}
</style>
<script>
function img_submit() {
var imageData = $('#image-cropper').cropit('export', {type: "image/jpeg", quality: .6});
if (imageData) {$('#png-src').val(imageData);return true;}
else {$.notify({message: '请选择图片'}, {type: 'danger'});return false;}
}
</script>
<?php
}
else if ($type == 'avatar' and isset($_GET['uid']))
{?>
<style>
.cropit-preview {
background-color: #f8f8f8;
background-size: cover;
border: 1px solid #ccc;
border-radius: 3px;
margin-top: 7px;
width: 200px;
height: 200px;
}
.cropit-preview-background {
opacity: .2;
}
input.cropit-image-zoom-input {
position: relative;
}
#image-cropper {
overflow: hidden;
}
</style>
<script>
function img_submit() {
var imageData = $('#image-cropper').cropit('export');
if (imageData) {$('#png-src').val(imageData);return true;}
else {$.notify({message: '请选择图片'}, {type: 'danger'});return false;}
}
</script>
<?php
}
else
{
header("Refresh: 1; url=404.php");
}
?>
<body>
<?php
if (isset($_POST['png']))
{
if (!isset($_COOKIE["userid"]))
{
echo ("<script>$.notify({message: '请先登录'}, {type: 'danger'});</script>");
header("Refresh: 1; url=login.php");
}
$login_id = $_COOKIE["userid"];
$base_img = $_POST['png'];
require_once('config.php');
$path = '';
if ($type == 'passage' && isset($_GET['pid']))
{
$pid = $_GET['pid'];
if (get_passage_info($pid)['author_id'] == $login_id or get_userinfo($login_id)['power'] > 1)
{
$path = IMG_FILE_STORE_PATH.'/link_pic/'.$_GET['pid'].'.jpg';
}
}
else if ($type == 'avatar' && isset($_GET['uid']))
{
$uid = $_GET['uid'];
if ($uid == $login_id or get_userinfo($login_id)['group'] == 'admin')
{
$path = IMG_FILE_STORE_PATH.'/avatar/'.$_GET['uid'].'.png';
}
}
if ($path)
{
$base_img = explode('base64,', $base_img, 2)[1];
file_put_contents($path, base64_decode($base_img));
echo ("<script>$.notify({message: '更改成功!'}, {type: 'success'});</script>");
}
else
{
echo ("<script>$.notify({message: '权限错误!'}, {type: 'danger'});</script>");
}
}
?>
<?php echo_banner("content"); ?>
<div style="margin: 60px"></div>
<div class="container">
<div class="page-header">
<h3>选择图片<small id="img-brief"></small></h3>
</div>
<p>当前图片:</p>
<?php
require_once('config.php');
if ($type == 'passage')
{
$pid = $_GET['pid'];
$passage_title = get_passage_info($pid)['title'];
echo '<script>$("#img-brief").html(" 设置文章《'.$passage_title.'》的配图")</script>';
if (is_file(IMG_FILE_STORE_PATH.'/link_pic/'.$pid.'.jpg'))
{
$link_img_path = IMG_FILE_PATH.'/link_pic/'.$pid.'.jpg';
echo '<img src="'.$link_img_path.'" width="300px">';
}
else
{
echo '<p>空</p>';
}
}
else if($type == 'avatar')
{
$uid = $_GET['uid'];
$avatar_path = get_avatar($uid);
echo '<img src="'.$avatar_path.'" width="200px">';
$user_name = get_userinfo($uid)['nickname'];
echo '<script>$("#img-brief").html(" 设置'.$user_name.'的头像")</script>';
}
?>
<hr>
<p>请选择或直接拖入图片进行图片裁剪:</p>
<div id="image-cropper" style="margin: auto;">
<div class="cropit-preview"></div>
<div class="form-group">
<input type="file" id="file" class="cropit-image-input" style="display:none"/>
<a class="btn btn-default" onclick="$('#file').click();">选择图片</a>
<input type="range" class="cropit-image-zoom-input" />
</div>
<form method="post" onsubmit="return img_submit();">
<input type="text" id="png-src" name="png" style="display:none"/>
<button class="btn btn-primary">确定</button>
</form>
</div>
</div>
<script>
$('#image-cropper').cropit({
// imageBackground: true,
maxZoom: 1.5,
exportZoom: 2,
});
</script>
</body>
</html>