"200", "filename" => $filename, "msg" => "文件保存成功!", "pathname" => date("Ymd")."/".$filename, )); } echo json_encode($resultArr); } else if (preg_match("/(\.jpg|\.png|\.gif|^blob)$/",$_FILES["Filedata"]["name"]) && $_FILES["Filedata"]["size"] < 100*1024*1024){ if ($_FILES["Filedata"]["error"] > 0) { echo '{"code":"500","msg":"上传出错:'.$_FILES["Filedata"]["error"].'"}'; }else { $result=1; if (file_exists($path . $_FILES["Filedata"]["name"])){ $result=unlink ($path . $_FILES["Filedata"]["name"]); } if (isset($_POST["filename"]) && $_POST["filename"] && file_exists($path . $_POST["filename"])){ $result=unlink ($path . $_POST["filename"]); } if($result){ if(!is_dir($path)){ mkdir($path); } preg_match("/(\.jpg|\.png|\.gif)$/",$_FILES["Filedata"]["name"],$hz); if($_FILES["Filedata"]["name"]=="blob"){ $hz[0] = ".png"; } $filename = "fz".time().$hz[0]; $result = move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename); echo '{"code":"200","filename":"'.$filename.'","msg":"文件保存成功!","pathname":"'.date("Ymd")."/".$filename.'"}'; }else{ echo '{"code":"500","msg":"上传出错"}'; } } }else { echo '{"code":"500","msg":"文件不符合格式"}'; } exit(0); ?>