$maxFileSize) { $_SESSION['error'] = "File is too large."; header("Location: upload.php"); exit; } // Get file extension and mime type $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); if (!in_array($ext, $allowedFileTypes)) { $_SESSION['error'] = "File type not allowed."; header("Location: upload.php"); exit; } if (!in_array($file['type'], $allowedMimeTypes)) { $_SESSION['error'] = "MIME type not allowed."; header("Location: upload.php"); exit; } // Create a unique temporary filename $uniqueName = uniqid() . "." . $ext; $destination = $tmpPath . $uniqueName; if (!move_uploaded_file($file['tmp_name'], $destination)) { $_SESSION['error'] = "Failed to save uploaded file."; header("Location: upload.php"); exit; } // Process the file: if mp3, extract metadata; if zip, extract each mp3's metadata. $uploadTask = []; $uploadTask['original_name'] = $file['name']; $uploadTask['local_path'] = $destination; $uploadTask['size'] = $file['size']; $uploadTask['ext'] = $ext; if ($ext === "mp3") { // Process MP3 file using shell_exec calls (ensure you sanitize arguments) $escapedFile = escapeshellarg($destination); $artist = trim(shell_exec("eyed3 --query='%a%' $escapedFile")); $title = trim(shell_exec("eyed3 --query='%t%' $escapedFile")); $duration = trim(shell_exec("mp3info -p \"%S\" $escapedFile")); // You can extract additional info as needed $uploadTask['file_type'] = 'mp3'; $uploadTask['metadata'] = [ 'artist' => $artist, 'title' => $title, 'duration' => $duration, // in seconds ]; $uploadTask['mediaplayer'] = 1; } elseif ($ext === "zip") { // Process ZIP file using ZipArchive $zip = new ZipArchive; if ($zip->open($destination) === true) { $totalDuration = 0; $tracklist = []; for ($i = 0; $i < $zip->numFiles; $i++) { $entryName = $zip->getNameIndex($i); $entryExt = strtolower(pathinfo($entryName, PATHINFO_EXTENSION)); if ($entryExt === "mp3") { // Extract the MP3 temporarily to process metadata $tempDir = $tmpPath . uniqid('zip_'); mkdir($tempDir); $tempFilePath = $tempDir . '/' . basename($entryName); $zip->extractTo($tempDir, $entryName); $escapedFile = escapeshellarg($tempFilePath); $title = trim(shell_exec("eyed3 --query='%t%' $escapedFile")); $duration = trim(shell_exec("mp3info -p \"%S\" $escapedFile")); $tracklist[] = $title ?: basename($entryName); $totalDuration += (int)$duration; unlink($tempFilePath); rmdir($tempDir); } } $zip->close(); $uploadTask['file_type'] = 'zip'; $uploadTask['metadata'] = [ 'tracklist' => $tracklist, 'total_duration' => $totalDuration, ]; // Mark ZIPs as download only (no mediaplayer) $uploadTask['mediaplayer'] = 0; } else { $_SESSION['error'] = "Failed to open ZIP file."; header("Location: upload.php"); exit; } } else { $_SESSION['error'] = "Unsupported file type."; header("Location: upload.php"); exit; } // Save the upload task details in session so step 2 can use them. $_SESSION['upload_task'] = $uploadTask; header("Location: upload_details.php"); exit; } require_once 'includes/header.php'; ?>

Upload a New Mix

' . htmlspecialchars($_SESSION['error']) . '
'; unset($_SESSION['error']); } ?>