PHP Code:
if(isset($_POST["btn-vd-submit"]) AND $vd_perm_actual > 0) {
$filename = $_FILES['vdfile']['name'];
$target_dir = "./voice-demo-files/";
$target_file = $target_dir . basename($_FILES['vdfile']['name']);
$uploadOk = 1;
$vdFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES['vdfile']['size'] > 50000000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($vdFileType != "mp3") {
echo "Sorry, only mp3 files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES['vdfile']['tmp_name'], $target_file)) {
echo "The file ". basename( $_FILES['vdfile']['name']). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
HTML Form:
<form class="custom-form" method="post" enctype="multipart/form-data">
<div class="s-4 m-4 center">
<center>Choose A Voice Demo File (.mp3) to upload and link with your profile:<br><br><br>
<input type="file" name="vdfile" id="vdfile"><br><br><br>
</div>
<div class="s-4 m-4 center">
<button class="submit-form center button background-primary text-white" name="btn-vd-submit" type="submit">Upload This Voice Demo!</button>
</div>
When I select and upload a file, I get the custom error message I set, "Sorry, there was an error uploading your file."; I don't get any kind of php error displayed on the page or in the logs but when I check the directory the file is not uploaded.