-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
203 lines (184 loc) · 6.61 KB
/
upload.php
File metadata and controls
203 lines (184 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
require_once 'config.php';
require_once 'functions.php';
if (!isLoggedIn() || $_SESSION['user_type'] != 'Artist') {
redirect('login.php');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['song_file']) && isset($_FILES['cover_photo']) && !empty($_POST['title'])) {
$user_id = $_SESSION['user_id'];
$title = sanitizeInput($_POST['title']);
$release_date = sanitizeInput($_POST['release_date']);
$language = sanitizeInput($_POST['language']);
$details = sanitizeInput($_POST['details']);
$genre = sanitizeInput($_POST['genre']);
$song_file = $_FILES['song_file'];
$cover_photo = $_FILES['cover_photo'];
// Validate song file
if ($song_file['error'] !== UPLOAD_ERR_OK) {
echo "Error uploading song file: " . $song_file['error'];
exit;
}
$allowed_song_types = ['audio/mpeg'];
if (!in_array($song_file['type'], $allowed_song_types)) {
echo "Invalid song file type. Only MP3 files are allowed.";
exit;
}
// Validate cover photo
if ($cover_photo['error'] !== UPLOAD_ERR_OK) {
echo "Error uploading cover photo: " . $cover_photo['error'];
exit;
}
$allowed_photo_types = ['image/jpeg', 'image/png'];
if (!in_array($cover_photo['type'], $allowed_photo_types)) {
echo "Invalid cover photo type. Only JPEG and PNG files are allowed.";
exit;
}
$upload_dir = 'uploads/';
$song_file_name = basename($song_file['name']);
$cover_file_name = basename($cover_photo['name']);
$song_file_path = $upload_dir . $song_file_name;
$cover_file_path = $upload_dir . $cover_file_name;
// Check if the files already exist
if (file_exists($song_file_path) || file_exists($cover_file_path)) {
echo "One or both files already exist. Please rename the files.";
exit;
}
// Attempt to move the uploaded files
if (move_uploaded_file($song_file['tmp_name'], $song_file_path) && move_uploaded_file($cover_photo['tmp_name'], $cover_file_path)) {
// Insert song metadata into database
$sql = "INSERT INTO Song (URL, cover_photo_url, Release_date, language, details, title, approval, genre, artist_id) VALUES (?, ?, ?, ?, ?, ?, FALSE, ?, ?)";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "sssssssi", $song_file_path, $cover_file_path, $release_date, $language, $details, $title, $genre, $user_id);
if (mysqli_stmt_execute($stmt)) {
echo "Song and cover photo uploaded successfully.";
} else {
echo "Error inserting song metadata: " . mysqli_error($conn);
}
mysqli_stmt_close($stmt);
} else {
echo "Error preparing statement: " . mysqli_error($conn);
}
} else {
echo "Failed to move uploaded files.";
}
}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Song</title>
<link rel="stylesheet" href="style.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #121212;
}
.container {
display: flex;
max-width: 1200px;
margin: 0 auto;
}
.sidebar {
flex: 1;
background: #1a1a1a;
color: #121212;
padding: 20px;
}
.sidebar .logo img {
width: 150px;
height: auto;
}
.sidebar nav ul {
list-style: none;
padding: 0;
}
.sidebar nav ul li {
margin: 10px 0;
}
.sidebar nav ul li a {
color: #fff;
text-decoration: none;
}
.main-content {
flex: 3;
padding: 20px;
background: #121212;
border-left: 0px solid #ccc;
}
.main-content h1 {
margin-bottom: 20px;
color: #fff;
}
form {
display: flex;
flex-direction: column;
gap: 15px;
}
label {
font-weight: bold;
margin-bottom: 5px;
}
input[type="text"],
input[type="date"],
textarea,
input[type="file"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
button {
padding: 10px;
background-color: #5cb85c;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #4cae4c;
}
</style>
</head>
<body>
<div class="container">
<div class="sidebar">
<div class="logo">
<img src="logo.png" alt="Phonic Hub Logo">
</div>
<nav>
<ul>
<li><a href="dashboard.php">Home</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="upload.php">Upload Song</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</div>
<div class="main-content">
<form action="upload.php" method="POST" enctype="multipart/form-data">
<h1>Upload New Song</h1>
<label for="title">Title:</label>
<input type="text" name="title" id="title" required>
<label for="release_date">Release Date:</label>
<input type="date" name="release_date" id="release_date" required>
<label for="language">Language:</label>
<input type="text" name="language" id="language" required>
<label for="details">Details:</label>
<textarea name="details" id="details" rows="4" required></textarea>
<label for="genre">Genre:</label>
<input type="text" name="genre" id="genre" required>
<label for="song_file">Upload MP3:</label>
<input type="file" name="song_file" id="song_file" accept="audio/mpeg" required>
<label for="cover_photo">Upload Cover Photo:</label>
<input type="file" name="cover_photo" id="cover_photo" accept="image/jpeg,image/png" required>
<button type="submit">Upload</button>
</form>
</div>
</div>
</body>
</html>