PHP代码:
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 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>
当我选择并上传文件时,收到我设置的自定义错误消息,&#34;抱歉,上传文件时出错。&#34 ;; 我没有在页面或日志中显示任何类型的php错误,但是当我检查目录时文件没有上传。