我有一个包含3个单独文件输入字段的表单.在将它们上传到服务器之前,我似乎无法找到单独验证其MIME类型的方法.(前两个应该只允许MP3文件,而最后一个只允许JPEG文件.)
我该怎么做,或者最好在上传文件后检查MIME类型,然后保留它,或者删除它并返回错误信息?
这是我的代码:
<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="col-2">
<label>
Full MP3 file
<input type="file" name="file_array[]" id="file_array[]" tabindex="1" required>
</label>
</div>
<div class="col-2">
<label>
Sample MP3 file (30-45 seconds)
<input type="file" name="file_array[]" id="file_array[]" tabindex="2" required>
</label>
</div>
<div class="col-2">
<label>
JPEG Cover Art ( Recommended 400 x 400 px)
<input type="file" name="file_array[]" id="file_array[]" tabindex="3" required>
</label>
</div>
<div class="col-2">
<label>
<progress id="progressBar" value="0" max="100" style="width:100%;"> </progress>
</label>
</div>
<div class="col-submit">
<input type="submit" value="Upload" class="submitbtn" onclick="uploadFile()">
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
这是upload.php
if(isset($_FILES['file_array'])){
$name_array …Run Code Online (Sandbox Code Playgroud)