38516-vm/upload_audio.php
2026-02-17 14:31:54 +00:00

25 lines
640 B
PHP

<?php
declare(strict_types=1);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['audio_file'])) {
$file = $_FILES['audio_file'];
// Validate file type
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
if (strtolower($ext) !== 'mp3') {
die("Only MP3 files are allowed.");
}
// Move to sahur.mp3
$destination = __DIR__ . '/sahur.mp3';
if (move_uploaded_file($file['tmp_name'], $destination)) {
header("Location: index.php?upload=success");
exit;
} else {
die("Failed to move uploaded file.");
}
} else {
header("Location: index.php");
exit;
}