You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.2 KiB
61 lines
2.2 KiB
<?php
|
|
require_once "database.php";
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$do_ins = true;
|
|
$input = &$_POST;
|
|
$data = array_reduce(array(
|
|
"facilityno", "sitename", "siteaddress", "ngdescribe", "creater"
|
|
), function ($acc, $key) use ($input) {
|
|
switch ($key) {
|
|
default:
|
|
$acc[$key] = htmlspecialchars(stripslashes(trim($input[$key])));
|
|
}
|
|
return $acc;
|
|
}, array("create_at" => date("Y-m-d H:i:s")));
|
|
|
|
if ($_FILES) {
|
|
$upd_base_path = "/wms/ngfeedback-uploads";
|
|
if (!is_dir($_SERVER["DOCUMENT_ROOT"] . "/" . $upd_base_path)) {
|
|
mkdir($_SERVER["DOCUMENT_ROOT"] . "/" . $upd_base_path, 0777, true);
|
|
}
|
|
// file_put_contents("./izumi_debug.log", print_r($_FILES, true)."\r\n", FILE_APPEND);
|
|
if ($_FILES["ngimage"]["error"] == UPLOAD_ERR_OK) {
|
|
# 將檔案移至指定位置
|
|
$data["ngimage"] = $upd_base_path . "/" . implode("__", array($data["facilityno"], strtotime($data["create_at"]))) . "." . pathinfo($_FILES["ngimage"]["name"], PATHINFO_EXTENSION);
|
|
move_uploaded_file($_FILES["ngimage"]["tmp_name"], $_SERVER["DOCUMENT_ROOT"] . "/" . $data["ngimage"]);
|
|
} else {
|
|
$do_ins = false;
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增失敗,請重新操作[F]')";
|
|
echo "</script>";
|
|
}
|
|
}
|
|
if ($do_ins) {
|
|
$db_query = sprintf("INSERT INTO ngfeedback (%s) VALUES (%s)",
|
|
implode(",", array_keys($data)),
|
|
implode(",", array_fill(0, count($data), "?")));
|
|
$stmt = $link->prepare($db_query);
|
|
// 此處僅有字串格式
|
|
$stmt->bind_param(implode("", array_fill(0, count($data), "s")), ...array_values($data));
|
|
$stmt->execute();
|
|
if ($mid = mysqli_insert_id($link)) {
|
|
// header("Location: );
|
|
if (mysqli_affected_rows($link) > 0) {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增成功');";
|
|
echo "window.location.href='/wms/ngfeedback-index.php?function_name=ngfeedback&token=".$_POST["token"]."';";
|
|
echo "</script>";
|
|
//header("Location: pricereview-index.php");
|
|
} else {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增失敗,請重新操作[I]')";
|
|
echo "</script>";
|
|
}
|
|
} else {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增失敗,請重新操作[M]')";
|
|
echo "</script>";
|
|
}
|
|
}
|
|
}
|
|
?>
|