食用方法
<?php
header("Access-Control-Allow-Origin:*");
header("Content-type: application/json; charset=utf-8");
if ($_GET['action'] == 'upload') {
$tmp_name =$_FILES['file']['tmp_name'];
if(!in_array($_FILES["file"]["type"],array("image/jpeg","image/gif","image/png")))exit();
switch ($_FILES["file"]["type"]){
case 'image/jpeg':
$type = 'jpg';
break;
case 'image/gif':
$type = 'gif';
break;
case 'image/png':
$type = 'png';
break;
default:
exit();
}
$picname = md5(time()).'.'.$type;
$status = move_uploaded_file($tmp_name,dirname(__FILE__).'/img/'.$picname);
if($status) {
$value = array(
'code'=> 0,
'msg'=> '上传成功',
'data'=> array('src'=> '输出路径'.$picname.'')
);
} else {
$value = array(
'code'=> 1,
'msg'=> '上传失败',
'data'=> array('src'=> '输出地址')
);
}
echo json_encode($value,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
}