'필수값 누락 (product_code, sw_version, filename)']); exit; } // === 제품 코드 → 실제 폴더명 매핑 === $map = [ "1" => "eg-bim", "2" => "tova", "3" => "gaia", "999" => "test" ]; $folder = $map[$product_code] ?? $product_code; // 혹시 매핑 없으면 그대로 사용 // === 업로드 경로 === // ex) eg-bim/1.2.3/setup_eg-bim_1.2.3.exe $key = "{$folder}/{$sw_version}/{$filename}"; try { $credentials = new Credentials($access_key, $secret_key); $s3 = new S3Client([ 'region' => 'auto', 'version' => 'latest', 'endpoint' => "https://{$account_id}.r2.cloudflarestorage.com", 'credentials' => $credentials, ]); // Presign URL 생성 $cmd = $s3->getCommand('PutObject', [ 'Bucket' => $bucket_name, 'Key' => $key, 'ContentType' => $content_type ]); $request = $s3->createPresignedRequest($cmd, '+1 hour'); echo json_encode([ 'url' => (string)$request->getUri(), // 브라우저에서 PUT 할 주소 'key' => $key // DB에 저장할 전체 경로 ]); } catch (Exception $e) { http_response_code(500); echo json_encode([ 'error' => 'Presign 실패', 'detail' => $e->getMessage() ]); } ?>