【发布时间】:2017-05-26 06:14:54
【问题描述】:
我正在尝试上传音频文件。
我正在做的是通过 Ajax 将音频文件传递到 PHP,在那里将完成上传和其他插入到我的数据库的操作。
通过 Ajax 传递后,我的 PHP 页面看不到音频文件。
<script type="text/javascript">
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
document.getElementById("load").style.display = "block";
textarea = $('#editor-one').html();
var formData = new FormData($(this)[0]);
formData.append("content", textarea);
$.ajax({
type: 'post',
url: 'verimg.php?ins=newmu',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data){
document.getElementById("load").style.display = "none";
//alert(textarea);
jQuery('#get_result').html(data).show();
}
});
});
});
</script>
这是我的 PHP 代码:
if(!isset($_FILES['file'])){
echo '<div class="alert alert-warning">
<strong>Warning!</strong> Please select an audio
</div>';
}else{
$uploaderror='';
$name = ucfirst($_POST['name']);
$artist = $_POST['artist'];
$content = $_POST['content'];
$genre = $_POST['genre'];
$validator = new FormValidator();
$validator->addValidation("name","req","Please fill in Music Name");
$validator->addValidation("category","req","Please Select Artist");
$validator->addValidation("category","req","Please Select Genre");
}
我总是收到“警告!请选择音频”。
【问题讨论】:
-
<input type="file">字段的name是什么?是“文件”吗? -
是的@LouysPatriceBessette
标签: javascript php jquery ajax audio