I've successfully uploaded the mp3 file to the server (local), and I'm trying to move the file to the destination folder which is located in the /opt/lampp/htdocs
folder and folder name is songs. But the file is not being moved to the folder.
This is my html code for uploading file (I'm trying to move an mp3 file):
<form method="post" action="../scripts/saveAudio.php" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="song"><br></br>
<div class="uploadbtn" align="center"><input type="submit" name="upload" value="Upload"></div>
</form>
And this is php code:
<?php
if(isset($_POST['upload'])){
if (($_FILES['song']['type'] == "audio/mpeg"))
{
$tempName = $_FILES['song']['tmp_name'][$key];
$desPath = "../songs/" . $_FILES['song']['name'];
if ($_FILES['song']['error'] > 0)
{
header('Location: ../src/uploadSongs.html');
exit();
}
if (file_exists("../songs/" . $_FILES['song']['name']))
{
echo $_FILES['file']['name'] . " already exists. ";
}
if(!move_uploaded_file($tempName, $desPath))
{
echo "File can't be uploaded";
}
}
else
{
echo "Please Upload MP3 files only";
}
}
?>