메인 배너 영상재생 기능추가.

This commit is contained in:
2025-12-15 17:55:17 +09:00
parent d125d39965
commit 40c757ea36
3 changed files with 244 additions and 35 deletions

View File

@ -29,6 +29,26 @@ if (!sql_query("SELECT bn_device FROM rb_banner LIMIT 0, 1")) {
sql_query("UPDATE rb_banner SET bn_device = 'pc'", true);
}
// 콘텐츠 유형 필드 추가 (image/video/video_url/youtube/vimeo)
if (!sql_query("SELECT bn_content_type FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_content_type` varchar(20) NOT NULL DEFAULT 'image' AFTER `bn_device`", true);
}
// 비디오 URL 필드 추가
if (!sql_query("SELECT bn_video_url FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_video_url` varchar(500) NOT NULL DEFAULT '' AFTER `bn_content_type`", true);
}
// 유튜브 URL 필드 추가
if (!sql_query("SELECT bn_youtube_url FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_youtube_url` varchar(500) NOT NULL DEFAULT '' AFTER `bn_video_url`", true);
}
// 비메오 URL 필드 추가
if (!sql_query("SELECT bn_vimeo_url FROM rb_banner LIMIT 0, 1")) {
sql_query("ALTER TABLE `rb_banner` ADD `bn_vimeo_url` varchar(500) NOT NULL DEFAULT '' AFTER `bn_youtube_url`", true);
}
include_once(G5_ADMIN_PATH . '/admin.head.php');
?>
@ -45,9 +65,23 @@ include_once(G5_ADMIN_PATH . '/admin.head.php');
</colgroup>
<tbody>
<tr>
<th scope="row"><label for="bn_content_type">콘텐츠 유형</label></th>
<td>
<?php echo help("배너의 콘텐츠 유형을 선택하세요."); ?>
<?php $bn_content_type = isset($bn['bn_content_type']) ? $bn['bn_content_type'] : 'image'; ?>
<select name="bn_content_type" id="bn_content_type" onchange="toggleContentInputs()">
<option value="image" <?php echo get_selected($bn_content_type, 'image', true); ?>>이미지</option>
<option value="video" <?php echo get_selected($bn_content_type, 'video', true); ?>>동영상 파일 (로컬 업로드)</option>
<option value="video_url" <?php echo get_selected($bn_content_type, 'video_url', true); ?>>비디오 URL (MP4, M3U8 등)</option>
<option value="youtube" <?php echo get_selected($bn_content_type, 'youtube', true); ?>>유튜브</option>
<option value="vimeo" <?php echo get_selected($bn_content_type, 'vimeo', true); ?>>비메오</option>
</select>
</td>
</tr>
<tr id="image_row">
<th scope="row">이미지</th>
<td>
<input type="file" name="bn_bimg">
<input type="file" name="bn_bimg" accept="image/*">
<?php
$bimg_str = "";
$bimg = G5_DATA_PATH . "/banners/" . $bn['bn_id'];
@ -66,6 +100,43 @@ include_once(G5_ADMIN_PATH . '/admin.head.php');
?>
</td>
</tr>
<tr id="video_row" style="display:none;">
<th scope="row">동영상 파일</th>
<td>
<?php echo help("MP4, MKV, MOV, WebM 등의 동영상 파일을 업로드하세요."); ?>
<input type="file" name="bn_video_file" accept="video/*">
<?php
if (isset($bn['bn_id']) && $bn['bn_id'] && $bn_content_type === 'video') {
$video_file = G5_DATA_PATH . "/banners/" . $bn['bn_id'];
if (file_exists($video_file)) {
echo '<div><p>업로드된 파일: ' . basename($video_file) . '</p>';
echo '<input type="checkbox" name="bn_video_del" value="1" id="bn_video_del"> <label for="bn_video_del">삭제</label></div>';
}
}
?>
</td>
</tr>
<tr id="video_url_row" style="display:none;">
<th scope="row">비디오 URL</th>
<td>
<?php echo help("MP4, M3U8, DASH 등의 비디오 파일 직접 URL을 입력하세요."); ?>
<input type="text" name="bn_video_url" value="<?php echo isset($bn['bn_video_url']) ? htmlspecialchars($bn['bn_video_url']) : ''; ?>" class="frm_input" size="80" placeholder="https://example.com/video.mp4">
</td>
</tr>
<tr id="youtube_row" style="display:none;">
<th scope="row">유튜브</th>
<td>
<?php echo help("유튜브 URL을 입력하세요. (예: https://www.youtube.com/watch?v=xxxxx 또는 https://youtu.be/xxxxx)"); ?>
<input type="text" name="bn_youtube_url" value="<?php echo isset($bn['bn_youtube_url']) ? htmlspecialchars($bn['bn_youtube_url']) : ''; ?>" class="frm_input" size="80" placeholder="https://www.youtube.com/watch?v=...">
</td>
</tr>
<tr id="vimeo_row" style="display:none;">
<th scope="row">비메오</th>
<td>
<?php echo help("비메오 URL을 입력하세요. (예: https://vimeo.com/xxxxx)"); ?>
<input type="text" name="bn_vimeo_url" value="<?php echo isset($bn['bn_vimeo_url']) ? htmlspecialchars($bn['bn_vimeo_url']) : ''; ?>" class="frm_input" size="80" placeholder="https://vimeo.com/...">
</td>
</tr>
<tr>
<th scope="row"><label for="bn_alt">메인타이틀</label></th>
<td>
@ -205,6 +276,20 @@ include_once(G5_ADMIN_PATH . '/admin.head.php');
</form>
<script>
function toggleContentInputs() {
const contentType = document.getElementById('bn_content_type').value;
document.getElementById('image_row').style.display = (contentType === 'image') ? 'table-row' : 'none';
document.getElementById('video_row').style.display = (contentType === 'video') ? 'table-row' : 'none';
document.getElementById('video_url_row').style.display = (contentType === 'video_url') ? 'table-row' : 'none';
document.getElementById('youtube_row').style.display = (contentType === 'youtube') ? 'table-row' : 'none';
document.getElementById('vimeo_row').style.display = (contentType === 'vimeo') ? 'table-row' : 'none';
}
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', toggleContentInputs);
</script>
<?php
include_once(G5_ADMIN_PATH . '/admin.tail.php');
?>

View File

@ -16,24 +16,60 @@ check_admin_token();
$bn_bimg = isset($_FILES['bn_bimg']['tmp_name']) ? $_FILES['bn_bimg']['tmp_name'] : null;
$bn_bimg_name = isset($_FILES['bn_bimg']['name']) ? $_FILES['bn_bimg']['name'] : null;
$bn_video_file = isset($_FILES['bn_video_file']['tmp_name']) ? $_FILES['bn_video_file']['tmp_name'] : null;
$bn_video_name = isset($_FILES['bn_video_file']['name']) ? $_FILES['bn_video_file']['name'] : null;
$bn_content_type = isset($bn_content_type) ? $bn_content_type : 'image';
$bn_video_url = isset($bn_video_url) ? clean_xss_tags($bn_video_url) : '';
$bn_youtube_url = isset($bn_youtube_url) ? clean_xss_tags($bn_youtube_url) : '';
$bn_vimeo_url = isset($bn_vimeo_url) ? clean_xss_tags($bn_vimeo_url) : '';
$bn_id = isset($bn_id) ? (int) $bn_id : 0;
$bn_bimg_del = isset($bn_bimg_del) ? $bn_bimg_del : null;
$bn_video_del = isset($bn_video_del) ? $bn_video_del : null;
if ($bn_bimg_del) {
@unlink(G5_DATA_PATH."/banners/$bn_id");
}
// 파일이 이미지인지 체크합니다.
if ($bn_bimg || $bn_bimg_name) {
if (!preg_match('/\.(gif|jpe?g|bmp|png)$/i', $bn_bimg_name)) {
alert("이미지 파일만 업로드 할 수 있습니다.");
}
if ($bn_video_del) {
@unlink(G5_DATA_PATH."/banners/$bn_id");
}
$timg = @getimagesize($bn_bimg);
if ($timg === false || $timg[2] < 1 || $timg[2] > 16) {
alert("이미지 파일만 업로드 할 수 있습니다.");
// 콘텐츠 유형에 따른 검증
if ($bn_content_type === 'image') {
// 파일이 이미지인지 체크합니다.
if ($bn_bimg || $bn_bimg_name) {
if (!preg_match('/\.(gif|jpe?g|bmp|png)$/i', $bn_bimg_name)) {
alert("이미지 파일만 업로드 할 수 있습니다.");
}
$timg = @getimagesize($bn_bimg);
if ($timg === false || $timg[2] < 1 || $timg[2] > 16) {
alert("이미지 파일만 업로드 할 수 있습니다.");
}
}
} elseif ($bn_content_type === 'video') {
// 동영상 파일 검증
if ($bn_video_file || $bn_video_name) {
if (!preg_match('/\.(mp4|mkv|mov|avi|webm|flv|wmv|m4v)$/i', $bn_video_name)) {
alert("동영상 파일(MP4, MKV, MOV, AVI, WebM, FLV, WMV, M4V)만 업로드 할 수 있습니다.");
}
}
} elseif ($bn_content_type === 'video_url') {
// URL 검증
if (!$bn_video_url) {
alert("비디오 URL을 입력하세요.");
}
} elseif ($bn_content_type === 'youtube') {
// 유튜브 URL 검증
if (!$bn_youtube_url) {
alert("유튜브 URL을 입력하세요.");
}
} elseif ($bn_content_type === 'vimeo') {
// 비메오 URL 검증
if (!$bn_vimeo_url) {
alert("비메오 URL을 입력하세요.");
}
}
@ -50,7 +86,22 @@ if(isset($_POST['bn_position_use']) && $_POST['bn_position_use']) {
}
if ($w == "") {
if (!$bn_bimg_name) alert('배너 이미지를 업로드 하세요.');
// 콘텐츠 유형별 필수 검사
if ($bn_content_type === 'image' && !$bn_bimg_name) {
alert('배너 이미지를 업로드 하세요.');
}
if ($bn_content_type === 'video' && !$bn_video_name) {
alert('동영상 파일을 업로드 하세요.');
}
if ($bn_content_type === 'video_url' && !$bn_video_url) {
alert('비디오 URL을 입력하세요.');
}
if ($bn_content_type === 'youtube' && !$bn_youtube_url) {
alert('유튜브 URL을 입력하세요.');
}
if ($bn_content_type === 'vimeo' && !$bn_vimeo_url) {
alert('비메오 URL을 입력하세요.');
}
sql_query("ALTER TABLE rb_banner AUTO_INCREMENT=1");
@ -61,6 +112,10 @@ if ($w == "") {
bn_alt4 = '$bn_alt4',
bn_url = '$bn_url',
bn_device = '$bn_device',
bn_content_type = '$bn_content_type',
bn_video_url = '$bn_video_url',
bn_youtube_url = '$bn_youtube_url',
bn_vimeo_url = '$bn_vimeo_url',
bn_position = '$bn_position',
bn_border = '$bn_border',
bn_radius = '$bn_radius',
@ -82,6 +137,10 @@ if ($w == "") {
bn_alt4 = '$bn_alt4',
bn_url = '$bn_url',
bn_device = '$bn_device',
bn_content_type = '$bn_content_type',
bn_video_url = '$bn_video_url',
bn_youtube_url = '$bn_youtube_url',
bn_vimeo_url = '$bn_vimeo_url',
bn_position = '$bn_position',
bn_border = '$bn_border',
bn_radius = '$bn_radius',
@ -100,9 +159,17 @@ if ($w == "") {
}
if ($w == "" || $w == "u") {
if (isset($_FILES['bn_bimg']['name']) && $_FILES['bn_bimg']['name']) {
rb_upload_files($_FILES['bn_bimg']['tmp_name'], $bn_id, G5_DATA_PATH."/banners");
// 콘텐츠 유형에 따라 파일 업로드
if ($bn_content_type === 'image') {
if (isset($_FILES['bn_bimg']['name']) && $_FILES['bn_bimg']['name']) {
rb_upload_files($_FILES['bn_bimg']['tmp_name'], $bn_id, G5_DATA_PATH."/banners");
}
} elseif ($bn_content_type === 'video') {
if (isset($_FILES['bn_video_file']['name']) && $_FILES['bn_video_file']['name']) {
rb_upload_files($_FILES['bn_video_file']['tmp_name'], $bn_id, G5_DATA_PATH."/banners");
}
}
// 나머지 타입(video_url, youtube, vimeo)은 파일 업로드 필요 없음 (URL만 저장)
goto_url("./banner_form.php?w=u&amp;bn_id=$bn_id");
} else {