-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.php
36 lines (32 loc) · 1012 Bytes
/
upload.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
<?php
function img_upload($name, $uploadPath="./", $upImageName=false) {
$type = $_FILES[$name]['type'];
if( $type == "image/gif" ) {$tail = '.gif';
}else if( $type == "image/jpeg" || $type == "image/jpg" || $type == "image/pjpeg" ) {$tail = '.jpg';
}else if( $type == "image/png" || $type == "image/x-png" ) {$tail = '.png';
}else {return false;}
if($upImageName){
$filename = $upImageName . $tail;
}else{
$filename = $name . $tail;
}
$fullname = $uploadPath . $filename;
if( ! move_uploaded_file($_FILES[$name]['tmp_name'], $fullname) ) {
return false;
}
switch ($type) {
case 1 : ImageGIF($im_out, $src); break;
case 2 : ImageJPEG($im_out, $src); break;
case 3 : ImagePNG($im_out, $src); break;
}
return $filename;
}
$res = img_upload("image", "./images/", "upload");
if($res){
$data = array('result' => true, 'filename' => $res);
}else{
$data = array('result' => false);
}
header('Content-type: text/html');
echo json_encode($data);
?>