-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload.php
More file actions
39 lines (33 loc) · 979 Bytes
/
upload.php
File metadata and controls
39 lines (33 loc) · 979 Bytes
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
<?php
//生成GUID
function create_guid(){
if (function_exists('com_create_guid')){
return com_create_guid();
}else{
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
$uuid = chr(123)// "{"
.substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12)
.chr(125);// "}"
return $uuid;
}
}
$photourl = create_guid();
$base_path = "./uploadimg/"; // 接收文件目录
$target_path = $base_path.$_FILES['file']['name'].".jpg";
if (move_uploaded_file ( $_FILES ['file'] ['tmp_name'], $target_path )) {
$array = array($photourl);
echo json_encode (array('photourl' => 'SUCCESS'));
} else {
$array = array (
"code" => "0",
"message" => "There was an error uploading the file, please try again!" . $_FILES ['file'] ['error']
);
echo json_encode ( $array );
}
?>