76 lines
2.6 KiB
PHP
76 lines
2.6 KiB
PHP
|
|
<?php
|
||
|
|
// 견적서 자료를 발주/수정으로 가져오는 것
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||
|
|
header("Content-Type: application/json");
|
||
|
|
|
||
|
|
ini_set('display_errors', 1);
|
||
|
|
ini_set('display_startup_errors', 1);
|
||
|
|
error_reporting(E_ALL);
|
||
|
|
|
||
|
|
// JSON 파일이 저장된 폴더 경로
|
||
|
|
$folderPath = $_SERVER['DOCUMENT_ROOT'] . '/output/json';
|
||
|
|
|
||
|
|
// 오늘 날짜 구하기
|
||
|
|
$today = date('Y-m-d');
|
||
|
|
|
||
|
|
// 폴더가 존재하는지 확인 오늘 이전의 자료를 삭제하는 코드이다.
|
||
|
|
if (is_dir($folderPath)) {
|
||
|
|
if ($dh = opendir($folderPath)) {
|
||
|
|
while (($file = readdir($dh)) !== false) {
|
||
|
|
$filePath = $folderPath . '/' . $file;
|
||
|
|
|
||
|
|
// 파일인지 확인 및 확장자가 .json인지 확인
|
||
|
|
if (is_file($filePath) && pathinfo($file, PATHINFO_EXTENSION) === 'json') {
|
||
|
|
// 파일의 권한 설정 (읽기, 쓰기, 삭제 가능)
|
||
|
|
chmod($filePath, 0666); // rw-rw-rw-
|
||
|
|
|
||
|
|
// 파일 수정 시간 가져오기
|
||
|
|
$fileModifiedTime = date('Y-m-d', filemtime($filePath));
|
||
|
|
|
||
|
|
// 파일 수정 날짜가 오늘 이전인지 확인
|
||
|
|
if ($fileModifiedTime < $today) {
|
||
|
|
// 파일 삭제
|
||
|
|
if (unlink($filePath)) {
|
||
|
|
echo "파일 삭제 성공: $filePath\n";
|
||
|
|
} else {
|
||
|
|
echo "파일 삭제 실패: $filePath\n";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
closedir($dh);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
echo "폴더가 존재하지 않습니다.";
|
||
|
|
}
|
||
|
|
|
||
|
|
// 폴더의 권한도 수정 (쓰기 가능하도록 설정)
|
||
|
|
// chmod($folderPath, 0777); // rwxrwxrwx
|
||
|
|
|
||
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
|
|
$jsonData = $_POST['jsonData'] ?? '';
|
||
|
|
$tempKey = $_POST['tempKey'] ?? '';
|
||
|
|
|
||
|
|
if ($jsonData && $tempKey) {
|
||
|
|
// json 폴더가 존재하지 않으면 생성
|
||
|
|
$jsonFolder = __DIR__ . '/json';
|
||
|
|
if (!is_dir($jsonFolder)) {
|
||
|
|
mkdir($jsonFolder, 0777, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
// JSON 파일 경로 생성
|
||
|
|
$filePath = $jsonFolder . '/' . $tempKey . '.json';
|
||
|
|
|
||
|
|
// JSON 데이터 파일에 저장
|
||
|
|
if (file_put_contents($filePath, $jsonData)) {
|
||
|
|
echo json_encode(['success' => true, 'message' => 'JSON 저장 성공']);
|
||
|
|
} else {
|
||
|
|
echo json_encode(['success' => false, 'message' => 'JSON 저장 실패']);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
echo json_encode(['success' => false, 'message' => '데이터가 올바르지 않습니다.']);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
echo json_encode(['success' => false, 'message' => '잘못된 요청입니다.']);
|
||
|
|
}
|
||
|
|
?>
|