-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuserupload.php
63 lines (47 loc) · 2.11 KB
/
userupload.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
<?php
include_once "pinyin.php";
$fore = $_POST['upload-input-fore'];
$mid = $_POST['upload-input-mid'];
$suffix = $_POST['upload-input-suffix'];
$file_result = $_FILES["user-upload"];
$file = $_FILES["user-upload"]["name"];
$file_suffix = substr($file,strpos($file,"."));
//数据库
require_once("password.php");
$conn = new mysqli($servername , $username, $password);
if ($conn -> connect_error) {
die("ERROR CONNECTING" . $conn -> connect_error);
}
mysqli_select_db($conn , "yiyandingzhen");
$total_pic_num = mysqli_fetch_array($conn -> query("SELECT COUNT(*) FROM yiyandingzhen"))[0] ;
$max_id = mysqli_fetch_array($conn -> query("SELECT MAX(pic_id) FROM yiyandingzhen"));
$pic_id = $max_id[0] + 1;
$new_file = $pic_id.'_'.Pinyin::getPinyin($fore).$file_suffix;
$savepath = "pic";
$file_type = image_type_to_mime_type(exif_imagetype($_FILES["user-upload"]["tmp_name"]));
if($file_type == "image/jpeg" || $file_type == "image/png" || $file_type == "image/gif" || $file_type == "image/jpg"){
move_uploaded_file($_FILES["user-upload"]["tmp_name"],$savepath."/".$new_file);
$SERVER = $_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
$pic_url = $savepath.'/'.$new_file;
$time = time();
$save_sql = "insert into yiyandingzhen (pic_id, fore, mid, suffix, pic_path, time, verified, beng) values ('$pic_id' ,'$fore', '$mid', '$suffix', '$pic_url', '$time', 0, 0)";
if ($conn->query($save_sql) === TRUE){
$sql_status = true;
}else{
$sql_status = false;
}
}else{
$sql_status = false;
}
//数据库保存
$retarr[] = array(
'result' => $file_result,
'file_suffix' => $file_suffix,
'new_file_name' => $new_file,
'pic_url' => $pic_url,
'id' => $pic_id,
'sql' => $sql_status,
'type' => $file_type
);
echo json_encode($retarr,JSON_UNESCAPED_UNICODE);
?>