-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuppic.php
More file actions
36 lines (28 loc) · 1.14 KB
/
uppic.php
File metadata and controls
36 lines (28 loc) · 1.14 KB
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
<?php
function guid(){
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtolower(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "_"
$uuid = substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
$uuid = strtolower($uuid);
return $uuid;
}
$file = $_FILES["pic"];
$path = "./content/uploads/photos/".date('Y/m',time());
$uploaded= false;
$url ="";
if($file){
$fpath=$file["tmp_name"];
$oname=$file["name"];
$tmp = explode(".",$oname);
$nname=guid().".".$tmp[count($tmp)-1];
move_uploaded_file($fpath,$path."/".$nname);
$url =$path."/".$nname;// 成功上传后 获取上传信息
$uploaded= true;
}
die(json_encode(['uploaded'=> $uploaded,'url'=>$url]));
?>