'latest', 'region' => $config['aws']['s3']['region'], 'endpoint' => $config['aws']['s3']['host'], 'credentials' => $credentials, 'use_path_style_endpoint' => true, 'profile' => null, // disable reading ~/.aws/config 'use_aws_shared_config_files' => false, ]); // Determine remote file path – for now, store in a temporary folder on Spaces $remotePath = "temp/mixes/" . uniqid() . "_" . basename($uploadTask['local_path']); // Determine MIME type from file extension $mimeType = ($uploadTask['ext'] === 'mp3') ? 'audio/mpeg' : 'application/zip'; try { $s3Client->putObject([ 'Bucket' => $config['aws']['s3']['bucket'], 'Key' => $remotePath, 'SourceFile' => $uploadTask['local_path'], 'ACL' => 'private', // file remains hidden until approved 'ContentType' => $mimeType, ]); } catch (Exception $e) { $_SESSION['error'] = "Error uploading file to CDN: " . $e->getMessage(); header("Location: upload_details.php"); exit; } // Now insert a new mix record into the database with pending status. $db = new Database($config); $stmt = $db->prepare("INSERT INTO mix (title, slug, description, cover, url, seconds, mediaplayer, dj1, dj2, dj3, pending, recorded) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?)"); // Determine the duration and mediaplayer flag from the upload task: // For an MP3 file, set mediaplayer to 0; for a ZIP file, set it to 1. $seconds = 0; if ($uploadTask['file_type'] === 'mp3') { $seconds = (int)$uploadTask['metadata']['duration']; $mediaplayer = 0; // MP3 gets a player } elseif ($uploadTask['file_type'] === 'zip') { $seconds = (int)$uploadTask['metadata']['total_duration']; $mediaplayer = 1; // ZIPs are download only, so flag them as 1 } // The URL can be constructed as per your CDN structure; for now, we store the remote path. $url = $remotePath; // For DJs, cast to integer (0 if none selected) $dj1 = (int)$dj1; $dj2 = (int)$dj2; $dj3 = (int)$dj3; $cover = ""; $stmt->bind_param("sssssiiiiss", $title, $slug, $description, $cover, $url, $seconds, $mediaplayer, $dj1, $dj2, $dj3, $recorded); if (!$stmt->execute()) { $_SESSION['error'] = "Error saving mix to database."; header("Location: upload_details.php"); exit; } $mixId = $stmt->insert_id; $stmt->close(); // Insert mix_meta entries for genres and tracklist // For genres, assume $selectedGenres is an array of genre IDs (or names, if new genres need to be added) foreach ($selectedGenres as $genreId) { $stmt = $db->prepare("INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'genre', ?)"); $stmt->bind_param("is", $mixId, $genreId); $stmt->execute(); $stmt->close(); } // If the file was mp3 and metadata includes a track title or tracklist, insert that as well: if ($uploadTask['file_type'] === 'mp3' && !empty($uploadTask['metadata']['title'])) { $tracklist = $uploadTask['metadata']['title']; $stmt = $db->prepare("INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'tracklist', ?)"); $stmt->bind_param("is", $mixId, $tracklist); $stmt->execute(); $stmt->close(); } elseif ($uploadTask['file_type'] === 'zip' && !empty($uploadTask['metadata']['tracklist'])) { // If multiple tracks, you might store them as a newline-separated string $tracklist = implode("\n", $uploadTask['metadata']['tracklist']); $stmt = $db->prepare("INSERT INTO mix_meta (mix_id, attribute, value) VALUES (?, 'tracklist', ?)"); $stmt->bind_param("is", $mixId, $tracklist); $stmt->execute(); $stmt->close(); } // Cleanup: delete the local temporary file and clear session task unlink($uploadTask['local_path']); unset($_SESSION['upload_task']); $_SESSION['success'] = "Mix uploaded successfully and is pending approval."; header("Location: profile.php"); exit; } require_once 'includes/header.php'; // Load available genres and DJs for the form $db = new Database($config); $genresObj = new DJMixHosting\Genres($db); $allGenres = $genresObj->get_all_genres(); $djsObj = new DJMixHosting\DJs($db); $allDJs = $djsObj->get_all_djs(); ?>

Enter Mix Details

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

Original Name:

File Type:

Size: KB

Duration: seconds

Total Duration: seconds