초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
36
email/save_pdf.php
Normal file
36
email/save_pdf.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
if (isset($_POST['pdf']) && isset($_POST['filename'])) {
|
||||
$pdf = $_POST['pdf'];
|
||||
$filename = $_POST['filename'];
|
||||
$pdfDir = $_SERVER['DOCUMENT_ROOT'] . '/pdfs/';
|
||||
$filePath = $pdfDir . $filename; // 저장할 경로
|
||||
|
||||
try {
|
||||
// PDFs 디렉토리가 존재하는지 확인하고 없으면 생성
|
||||
if (!is_dir($pdfDir)) {
|
||||
if (!mkdir($pdfDir, 0755, true)) {
|
||||
throw new Exception("PDF 디렉토리를 생성할 수 없습니다: {$pdfDir}");
|
||||
}
|
||||
}
|
||||
|
||||
// 디렉토리 쓰기 권한 확인
|
||||
if (!is_writable($pdfDir)) {
|
||||
throw new Exception("PDF 디렉토리에 쓰기 권한이 없습니다: {$pdfDir}");
|
||||
}
|
||||
|
||||
// PDF 파일 저장
|
||||
$result = file_put_contents($filePath, base64_decode($pdf));
|
||||
|
||||
if ($result === false) {
|
||||
throw new Exception("PDF 파일 저장에 실패했습니다: {$filePath}");
|
||||
}
|
||||
|
||||
echo json_encode(array('success' => true, 'filename' => $filename));
|
||||
} catch (Exception $e) {
|
||||
error_log("PDF 저장 오류: " . $e->getMessage());
|
||||
echo json_encode(array('success' => false, 'error' => $e->getMessage()));
|
||||
}
|
||||
} else {
|
||||
echo json_encode(array('success' => false, 'error' => 'Invalid request - PDF data or filename missing'));
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user