if($_POST){
$title=$_POST[‘title‘];
$descs=$_POST[‘descs‘];
$content=$_POST[‘content‘];
$uname=$_POST[‘img‘];
$conn=new mysqli(‘localhost‘,‘root‘,‘root‘,‘qiye‘);
$sql="insert into product (title,img,descs,content) values(‘$title‘,‘$uname‘,‘$descs‘,‘$content‘)";
$rel=$conn->query($sql);
$conn->close();
}
if($_FILES){
// var_dump($_FILES);
//获取文件后缀
$temp = explode(".", $_FILES["img"]["name"]);
$extension = end($temp);
//判断文件类型大小
if($_FILES[‘img‘][‘type‘] == "image/gif"||$_FILES[‘img‘][‘type‘]
== "image/jpeg"||$_FILES[‘img‘][‘type‘] == "image/jpg"||$_FILES[‘img‘][‘type‘]
== "image/png"&& $_FILES[‘img‘][‘size‘] <= 204800){
$uname=‘/uploads/‘.time().mt_rand(100,999).‘.‘.$extension;
move_uploaded_file($_FILES[‘img‘][‘tmp_name‘],‘../..‘.$uname);//文件放置路径
// $conn=new mysqli(‘localhost‘,‘root‘,‘root‘,‘qiye‘);
// $sql="insert into product (img) values(‘$uname‘)";
// $res=$conn->query($sql);
$data[‘code‘]=1;
$data[‘msg‘]=$uname;
echo json_encode($data);
}else{
$data[‘code‘]=2;
echo json_encode($data);
}
}