发现有好多开发者,上传图片总是无法很好的解决后端问题,其实是你思路有问题,以下代码是PHP如何接收并保存图片的,你觉得与网站有区别吗?
header("Contetn-Type:text/html;Charset=utf-8");
require_once('../include/upImg.php'); //上传图片加载类
$cid = $_REQUEST["cid"]; //企业ID
$uid = $_REQUEST["uid"]; //ID
if(empty($cid)){
$result['code']=0;
$result['info']="请关联相关的企业.";
}
if(empty($uid)){
$result['code']=0;
$result['info']="请关联相关的企业.";
}
if(empty($_FILES['img']['tmp_name'])){
$result['code']=0;
$result['info']="请选择相应的图片.";
}
$up=new upphoto();
$dir="../uploadImg/".date("Ymd")."/";
if(!is_dir($dir)){ //如果不存在当前日期的目录,创建目录
mkdir($dir, 0700);
}
$dir="../uploadImg/".date("Ymd")."/".$cid."/";
if(!is_dir($dir)){ //如果不存在当前企业的目录,创建目录
mkdir($dir, 0700);
}
$up->ph_path=$dir;
$up->datetime=$up->datetime.'_'.$uid;
$up->get_ph_tmpname($_FILES['img']['tmp_name']);
$up->get_ph_type($_FILES['img']['type']);
$up->get_ph_size($_FILES['img']['size']);
$up->get_ph_name($_FILES['img']['name']);
$up->check_path();
$photo=$up->save();
$result['code']=1;
$result['img']=$photo;
print_r(json_encode($result));
?>