-
Notifications
You must be signed in to change notification settings - Fork 0
/
fun.php
39 lines (22 loc) · 816 Bytes
/
fun.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
<?php
if (isset($_FILES['images']['name'])){
$targetDir = "uploads/";
$allowTypes = array('jpg','png','jpeg','gif');
foreach($_FILES['images']['name'] as $key=>$val){
$imgfile = $_FILES['images']['name'][$key];
$fileName = basename($_FILES['images']['name'][$key]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
$rand = rand(1, 1000000000);
$newname = $rand . date('Ymdhis');
if(in_array($fileType, $allowTypes)){
$filename = $_FILES['images']['tmp_name'][$key];
$finalname = $newname .'.'. $fileType;
if(move_uploaded_file($filename, $targetFilePath . $finalname)){
rename($targetFilePath.$newname.'.'.$fileType, $targetDir . $newname.'.'.$fileType);
}
}
}
echo json_encode('success');
}
?>