I want to only upload a file with extension name .mp3
.
I tried to upload file with this code:
index.php
:
<form action="upload.php" method="post" id="myForm" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" class="btn btn-success" value="Upload Image">
</form>
upload.php
:
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ($extension == "mp3"){
$target = "upload/";
move_uploaded_file($_FILES["file"]["tmp_name"], $target. $_FILES["file"]["name"]);
}
else {
echo "Failed";
}
What's wrong with my code?