I have two php files one with audio categories that allow a music selection when uploading MP3 and the other code is the audio file. I have it when MP3 files are uploaded it goes into a MP3 folder. I have other folders inside the MP3 folder which are the names of the category list (example: country folder, rock folder, etc) how can I get the MP3 files not to just go into the MP3 folder but when they are uploaded and a category selection is made it goes into that direct folder. Below are the codes:
Audiocat code:
<?php
include 'core/init.php';
include 'includes/overall/header.php';
if (isset($_GET['cat']) === true) {
$cat = $_GET['cat'];
$audios = all_audio($cat);
} else {
header('Location: /');
exit();
}
?>
<h1>Audio</h1>
<p>Viewing category <strong><?php echo audio_category_name_from_id($cat); ?></strong></p>
<?php
if (empty($audios) === true) {
?>
Sorry, there are no audio files in this category
<?php
} else {
foreach($audios as $audio) {
?>
<a href="listen.php?a=<?php echo $audio['audio_id']; ?>"><?php echo $audio['audio_file']; ?></a><br>
<?php
}
}
?>
<?php include 'includes/overall/footer.php'; ?>
Audio code:
<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
if (isset($_GET['delete']) === true) {
$delete = $_GET['delete'];
user_delete_audio($delete);
header('Location: audio.php');
}
?>
<h1>Your audio</h1>
<p>Users can listen to your audio on your profile page</p>
<?php
if (empty($_FILES) === false && isset($_POST['cat']) === true) {
$allowed = array('mp3');
$filename = $_FILES['audio_file']['name'];
$fileext = strtolower(end(explode('.', $filename)));
$tmp = $_FILES['audio_file']['tmp_name'];
$cat = $_POST['cat'];
if (in_array($fileext, $allowed) === false) {
?>
<p><strong>Sorry, only mp3 files are allowed to be uploaded</strong></p>
<?php
} else if (user_audio_count($_SESSION['user_id']) >= 5) {
?>
<p><strong>Maximum 5 files allowed, sorry.</strong></p>
<?php
} else {
if (cat_exists($cat) === false) {
?>
<p><strong>Something went really wrong here, sorry.</strong></p>
<?php
} else {
user_add_audio($filename . '-' . $_SESSION['user_id'], $cat);
move_uploaded_file($tmp, 'mp3/' . $filename . '-' . $_SESSION['user_id'] . '.mp3');
header('Location: audio.php');
}
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<p>
Add audio:
<input type="file" name="audio_file">
<select name="cat">
<?php
foreach(list_categories() as $cat) {
?>
<option value="<?php echo $cat['cat_id']; ?>"><?php echo $cat['category']; ?></option>
<?php
}
?>
</select>
<input type="submit" value="Upload">
</p>
</form>
<?php
$audios = user_audio($_SESSION['user_id']);
if (empty($audios) === true) {
?>
<p>You haven't added any audio files yet.</p>
<?php
} else {
foreach($audios as $audio) {
?>
<a href="listen.php?a=<?php echo $audio['audio_id']; ?>"><?php echo $audio['audio_file']; ?></a> in <?php echo audio_category_name_from_id($audio['cat_id']); ?> (<a href="audio.php?delete=<?php echo $audio['audio_id']; ?>">Delete</a>)<br>
<?php
}
}
include 'includes/overall/footer.php';
?>