<?php header('Content-Type:application/json; charset=utf-8'); if (isset($_REQUEST["pname"])) { $pname = $_REQUEST["pname"]; } else { $pname = "i/upload"; } $zdyfname = $_REQUEST["zdyfname"]; date_default_timezone_set('PRC'); if ($_FILES["file"]["name"] == "") { exit(json_encode(array( 'code' => 301, 'msg' => '没有选择文件!' ), JSON_UNESCAPED_UNICODE)); } else { $wjj = $pname . "/"; if (!is_readable($wjj)) { $oldmask = umask(0); is_file($wjj) or mkdir($wjj, 0777, true); chmod($wjj, 0777); umask($oldmask); } if ($zdyfname != "") { $filename = $zdyfname; } else { $filename = $_FILES["file"]["name"]; } $filename = str_replace("'", "''", $filename); $filename = str_replace(" ", " ", $filename); $filename = str_replace(" ", " ", $filename); if ($_FILES["file"]["name"] != "" && $_FILES["file"]["error"] == 0) { if (file_exists($pname . "/" . $filename)) { exit(json_encode(array( 'code' => 302, 'msg' => '同名文件 ' . $filename . ' 已存在,请删除原文件或将新文件重命名后再次上传!' ), JSON_UNESCAPED_UNICODE)); } else { move_uploaded_file($_FILES["file"]["tmp_name"], $pname . "/" . $filename); exit(json_encode(array( 'code' => 200, 'msg' => '上传成功', 'path' => $pname . "/" . $filename, 'pname' => $pname, 'filename' => $filename ), JSON_UNESCAPED_UNICODE)); } } else { if ($_FILES["file"]["error"] > 0) { exit(json_encode(array( 'code' => 303, 'msg' => '文件上传出错,请检查后重新上传!' ), JSON_UNESCAPED_UNICODE)); } } } ?>