diff --git a/api/upload_audio.php b/api/upload_audio.php new file mode 100644 index 0000000..c0bb67b --- /dev/null +++ b/api/upload_audio.php @@ -0,0 +1,41 @@ + false, 'error' => 'Invalid request method.']); + exit; +} + +if (!isset($_FILES['sahur_file'])) { + echo json_encode(['success' => false, 'error' => 'No file uploaded.']); + exit; +} + +$file = $_FILES['sahur_file']; + +// Basic validation +if ($file['error'] !== UPLOAD_ERR_OK) { + echo json_encode(['success' => false, 'error' => 'Upload error: ' . $file['error']]); + exit; +} + +$ext = pathinfo($file['name'], PATHINFO_EXTENSION); +if (strtolower($ext) !== 'mp3') { + echo json_encode(['success' => false, 'error' => 'Only MP3 files are allowed.']); + exit; +} + +$targetDir = __DIR__ . '/../assets/audio/'; +if (!is_dir($targetDir)) { + mkdir($targetDir, 0775, true); +} + +$targetPath = $targetDir . 'sahur.mp3'; + +if (move_uploaded_file($file['tmp_name'], $targetPath)) { + echo json_encode(['success' => true]); +} else { + echo json_encode(['success' => false, 'error' => 'Failed to save file.']); +} diff --git a/assets/audio/sahur.mp3 b/assets/audio/sahur.mp3 index e69de29..13d50ac 100644 Binary files a/assets/audio/sahur.mp3 and b/assets/audio/sahur.mp3 differ diff --git a/assets/js/main.js b/assets/js/main.js index 832d6bd..8cb5add 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -51,4 +51,58 @@ document.addEventListener('DOMContentLoaded', () => { testAudioBtn.textContent = 'Test Play Locally'; }); } + + // Sahur MP3 Upload Logic + const sahurUpload = document.getElementById('sahur-upload'); + const uploadBtn = document.getElementById('upload-btn'); + const uploadStatus = document.getElementById('upload-status'); + + if (sahurUpload && uploadBtn) { + sahurUpload.addEventListener('change', () => { + if (sahurUpload.files.length > 0) { + uploadBtn.style.display = 'block'; + uploadStatus.textContent = `Selected: ${sahurUpload.files[0].name}`; + } else { + uploadBtn.style.display = 'none'; + uploadStatus.textContent = ''; + } + }); + + uploadBtn.addEventListener('click', async () => { + if (sahurUpload.files.length === 0) return; + + const formData = new FormData(); + formData.append('sahur_file', sahurUpload.files[0]); + + uploadBtn.disabled = true; + uploadBtn.textContent = 'Uploading...'; + uploadStatus.textContent = 'Processing your file...'; + + try { + const response = await fetch('api/upload_audio.php', { + method: 'POST', + body: formData + }); + + const result = await response.json(); + + if (result.success) { + uploadStatus.innerHTML = '✓ Berhasil di-upload!'; + // Reload audio player to reflect the new file + const currentSrc = audioPlayer.querySelector('source').src; + audioPlayer.querySelector('source').src = currentSrc.split('?')[0] + '?v=' + Date.now(); + audioPlayer.load(); + } else { + uploadStatus.innerHTML = `Gagal: ${result.error}`; + } + } catch (error) { + uploadStatus.innerHTML = 'Network error.'; + } finally { + uploadBtn.disabled = false; + uploadBtn.textContent = 'Upload Now'; + uploadBtn.style.display = 'none'; + sahurUpload.value = ''; + } + }); + } }); diff --git a/assets/pasted-20260216-030726-b963f4b6.jpg b/assets/pasted-20260216-030726-b963f4b6.jpg new file mode 100644 index 0000000..ac64dfb Binary files /dev/null and b/assets/pasted-20260216-030726-b963f4b6.jpg differ diff --git a/assets/pasted-20260216-030952-fcd50289.jpg b/assets/pasted-20260216-030952-fcd50289.jpg new file mode 100644 index 0000000..c1e7861 Binary files /dev/null and b/assets/pasted-20260216-030952-fcd50289.jpg differ diff --git a/assets/pasted-20260216-031651-1b4392bf.jpg b/assets/pasted-20260216-031651-1b4392bf.jpg new file mode 100644 index 0000000..0b097a5 Binary files /dev/null and b/assets/pasted-20260216-031651-1b4392bf.jpg differ diff --git a/index.php b/index.php index c77799d..00a80aa 100644 --- a/index.php +++ b/index.php @@ -71,8 +71,15 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; Your browser does not support the audio element. -
+
+ +
+ + + +
+