使用layer的单张图片上传 public function upload() { if ($_FILES["file"]["error"] 0){ $result = [ 'state' = 0, 'msg' = '上传失败', 'filename' = '', ]; }else{ $time=date ('Y-m-d',time ()); $uploaddir = str_replace ('\\', '/', 'upl
public function upload() { if ($_FILES["file"]["error"] > 0){ $result = [ 'state' => 0, 'msg' => '上传失败', 'filename' => '', ]; }else{ $time=date ('Y-m-d',time ()); $uploaddir = str_replace ('\\', '/', 'uploads/'.$time.'/'); is_dir ($uploaddir)||mkdir ($uploaddir,0777,true); //获取当前图片的格式 $type = strrchr ($_FILES["file"]['name'], '.'); //将当前时间戳和图片格式拼接起来,形成图片路径 $fileDate = time ().$type; $uploadfile = $uploaddir.$fileDate; if (move_uploaded_file ($_FILES['file']['tmp_name'], $uploadfile)){ $result = [ 'state' => 1, 'msg' => '上传成功', 'filename' => $uploadfile, ]; }else{ $result = [ 'state' => 0, 'msg' => '上传失败', 'filename' => $uploadfile, ]; } } return json ($result); }