Php 如何使用ajax或jquery获得文件上传进度
如何使用ajax或jquery获得文件上传进度这是我的代码Php 如何使用ajax或jquery获得文件上传进度,php,jquery,ajax,Php,Jquery,Ajax,如何使用ajax或jquery获得文件上传进度这是我的代码 <form id="mid-form" id="upload_form" method="POST" enctype="multipart/form-data" action="includes/talent_upload_video.php"> <input type="hidden" id="target_id" name="target_id" value=
<form id="mid-form" id="upload_form" method="POST" enctype="multipart/form-data" action="includes/talent_upload_video.php">
<input type="hidden" id="target_id" name="target_id" value="<?php echo $_REQUEST['id']; ?>" />
<p style="text-align:center; padding:10px;"><span class="font18px">Upload Your Videos</span></p>
<p style="text-align:center;"><input type="file" name="picture" /></p>
<p style="text-align:center; padding:10px;">
<input type="submit" name="add_picture" value="ADD+" class="fontBold">
</form>
试试这个例子
脚本
$(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal);
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
}
});
});
Html
<form action="file-echo2.php" method="post" enctype="multipart/form-data">
<input type="file" name="myfile"><br>
<input type="submit" value="Upload File to Server">
</form>
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
0%
在发布问题之前,请确保遵循以下指导原则: