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.
102 lines
2.6 KiB
102 lines
2.6 KiB
<?php
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
show405Error();
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$request_data_json = file_get_contents('php://input');
|
|
$request_data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if (empty($request_data)) {
|
|
show400Error();
|
|
exit;
|
|
}
|
|
|
|
writePostIni($request_data);
|
|
writePostIniJson($request_data);
|
|
|
|
$fd_id = $request_data[$fd_id];
|
|
|
|
// $dsn = 'mysql:host=localhost;dbname=appwms_test';
|
|
// $username = 'masadaroot';
|
|
// $password = 'x6h5E5p#u8y';
|
|
// try {
|
|
// $pdo = new PDO($dsn, $username, $password);
|
|
// $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
// $pdo->exec('SET CHARACTER SET utf8mb4');
|
|
// $pdo->beginTransaction();
|
|
// $sth = $pdo->prepare("INSERT INTO account (accounttype , accountid) VALUES (?, ?)");
|
|
// $sth->bindValue(1, 'mf_vol_no');
|
|
// $sth->execute();
|
|
// $pdo->commit();
|
|
// showSuccessMessage();
|
|
// } catch (PDOException $e) {
|
|
// $pdo->rollBack();
|
|
// echo "Transaction failed: " . $e->getMessage();
|
|
// }
|
|
|
|
}
|
|
|
|
function showSuccessMessage()
|
|
{
|
|
$response = array('status' => 'success', 'message' => 'Data received and stored successfully');
|
|
header('Content-Type: application/json');
|
|
echo json_encode($response);
|
|
}
|
|
|
|
function showErrorMessage()
|
|
{
|
|
$response = array('status' => 'error', 'message' => 'Data received and stored error');
|
|
header('Content-Type: application/json');
|
|
echo json_encode($response);
|
|
}
|
|
|
|
function show400Error()
|
|
{
|
|
http_response_code(400);
|
|
echo 'Invalid request data';
|
|
}
|
|
|
|
function show405Error()
|
|
{
|
|
http_response_code(405);
|
|
echo 'Method Not Allowed';
|
|
}
|
|
|
|
function writePostIni($request_data)
|
|
{
|
|
// 讀取現有 ini 檔案的資料
|
|
$ini_file = 'addConstructOutsource.ini';
|
|
$existing_data = parse_ini_file($ini_file, true);
|
|
|
|
// 將接收到的資料加入現有資料
|
|
$timestamp = time();
|
|
$existing_data[$timestamp] = $request_data;
|
|
|
|
// 將資料寫入 ini 檔
|
|
$ini_content = '';
|
|
foreach ($existing_data as $key => $value) {
|
|
$ini_content .= "[$key]\n";
|
|
foreach ($value as $k => $v) {
|
|
$ini_content .= "$k = \"$v\"\n";
|
|
}
|
|
$ini_content .= "\n";
|
|
}
|
|
|
|
file_put_contents($ini_file, $ini_content);
|
|
}
|
|
|
|
|
|
function writePostIniJson($request_data)
|
|
{
|
|
$txt_file = 'addConstructOutsource.txt';
|
|
$txt = "";
|
|
$file = fopen($txt_file, 'a');
|
|
foreach($request_data as $k => $v){
|
|
$txt .= "$k = \"$v\"\n";
|
|
}
|
|
fwrite($file, $txt . PHP_EOL);
|
|
fclose($file);
|
|
}
|
|
|