-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalbums.php
126 lines (100 loc) · 3.9 KB
/
albums.php
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
<?php include "nav.php" ?>
<?php if (isset($_SESSION['username']) && $_SESSION['username']=='admin')
{
?>
<?php
if (isset($_POST['upload'])) {
$name = $_POST['album_name'];
$artist = $_POST['artist'];
$genre = $_POST['genre'];
$description = $_POST['description'];
if (!is_dir('uploads'))
{
mkdir('uploads', 0777, true);
}
if (!is_dir('uploads/images'))
{
mkdir('uploads/images', 0777, true);
}
if (file_exists("uploads/images" . $_FILES["album_cover"]["name"]))
{
echo $_FILES["album_cover"]["name"] . " already exists. ";
}
else
{
$file = $_FILES["album_cover"]["tmp_name"];
$filename = $_FILES["album_cover"]["name"];
$destination = "uploads/images/" . $_FILES["album_cover"]["name"];
if (move_uploaded_file($file, $destination)) {
$query = "INSERT into albums (name, cover, artist ,no_of_tracks, genre, description) VALUES ('$name', '$filename', '$artist' , 0, '$genre', '$description')";
if (mysqli_query($connection, $query)) {
echo "Stored in: " . "uploads/images/" . $_FILES["album_cover"]["name"];
}else{
echo "failed to upload file" . mysqli_error($connection) ;
}
}
}
}
?>
<form style="max-width: 80%; margin-left: 1rem; margin-top: 40px !important;" class="" action='' method='post' enctype='multipart/form-data'>
<br />
<label>Album name</label>
<input class="form-control" type=text name='album_name' />
<br />
<label>Artist</label>
<input class="form-control" type=text name='artist' />
<br />
<label>Album Cover</label>
<input class="form-control" type="file" name="album_cover" >
<br />
<label>Genre</label>
<input class="form-control" type="text" name="genre" >
<br />
<label>Description</label>
<input class="form-control" type="text" name="description" >
<br />
<input class="btn btn-outline b-black text-black" type='submit' name='upload' value='Add Album' />
</form>
<?php } ?>
<div class="app-body" id="view">
<div class="page-content">
<div class="row-col">
<div class="col-lg-9 b-r no-border-md">
<div class="padding">
<div class="page-title m-b">
<h1 class="inline m-a-0">Browse</h1>
</div>
<?php
$query = "SELECT * FROM albums";
$select_query = mysqli_query($connection, $query);
if ($select_query) {
while ($row= mysqli_fetch_assoc($select_query)) {
$id = $row['id'];
$name = $row['name'];
$artist = $row['artist'];
$cover = $row['cover'];
$no_of_tracks = $row['no_of_tracks'];
?>
<div class="col-xs-4 col-sm-4 col-md-3">
<div class="item r" data-id="item-5">
<div class="item-media"><a href="album.php?album_id=<?php echo $id ?>";"
class="item-media-content"
style="background-image: url(<?php echo 'uploads/images/' . $cover ; ?>)"></a>
</div>
<div class="item-info">
<div class="item-overlay bottom text-right">
</div>
<div class="item-title text-ellipsis">
<a href="album.php?album_id=<?php echo $id; ?>"><?php echo $name; ?></a>
</div>
<div class="item-author text-sm text-ellipsis"><a
class="text-muted"><?php echo $artist; ?></a></div>
</div>
</div>
</div>
<?php }} ?>
</div>
</div>
</div>
</div>
<?php include "footer.php" ?>