Android jquery fileupload在移动设备上不起作用
我在我的(基于php和jquery的)应用程序中使用带有进度条的jquery文件上传来上传视频,它在桌面上运行良好 但在移动设备上,当手机进入睡眠模式3-4分钟时,它会停止上传。 它在“非正在上载非MB的非MB”的进度中显示此信息 为什么会发生这种事?你知道吗Android jquery fileupload在移动设备上不起作用,android,jquery,wordpress,mobile,jquery-file-upload,Android,Jquery,Wordpress,Mobile,Jquery File Upload,我在我的(基于php和jquery的)应用程序中使用带有进度条的jquery文件上传来上传视频,它在桌面上运行良好 但在移动设备上,当手机进入睡眠模式3-4分钟时,它会停止上传。 它在“非正在上载非MB的非MB”的进度中显示此信息 为什么会发生这种事?你知道吗 jQuery(file_upload_selector).fileupload({ dropZone: $(this), url: url, dataType: 'text',
jQuery(file_upload_selector).fileupload({
dropZone: $(this),
url: url,
dataType: 'text',
async: true,
beforeSend: function(xhr) {
jQuery('.err').hide();
add_more.sort();
var file = this.files[0],
fl_type = file.type;
var mim_t = fl_type.split("/")[0];
//disable on max file count
if (section_type == 'video') {
for (var k = 0; k < 2; k++) {
var src = jQuery('#vd_image' + k).attr('src');
if (src == 'http://www.example.com/wp-content/themes/example/assets/images/video-placeholder.jpg') {
var onev = 1;
}
}
for (var k = 1; k < 6; k++) {
var src = jQuery('#vd_image' + k).attr('src');
if (src == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
var twov = 1;
}
}
} else {
for (var k = 0; k < 4; k++) {
var src2 = jQuery('#ch_image' + k).attr('src');
if (src2 == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
var hidevcon3 = 1;
}
}
}
if (onev == '1' && fl_type != 'video/mp4' && twov != '1') {
alert('Please upload video only');
return false;
}
// disable ends
if (section_type == 'video' && add_more[0] == "0" && mim_t == "video") {
jQuery('#_filechk').val(1);
jQuery(uploading_div_id + "-0").css("display", "block");
} else if (section_type == 'video' && add_more[0] == "0" && mim_t == "image") {
jQuery('#_filechk').val(0);
jQuery(uploading_div_id + "-" + add_more[0 + 1]).css("display", "block");
} else if (section_type == 'video' && add_more[0] != "0" && mim_t == "image") {
jQuery('#_filechk').val(0);
jQuery(uploading_div_id + "-" + add_more[0]).css("display", "block");
} else {
jQuery('#_filechk').val(0);
jQuery(uploading_div_id + "-" + add_more[0]).css("display", "block");
}
},
progressall: function(e, data) {
chckp = jQuery('#_filechk').val();
if (section_type == 'video') {
document.getElementById("ch_ima").disabled = true;
jQuery('#progressing').show();
jQuery('.cn-v').show();
var progress = parseInt(data.loaded / data.total * 100, 10);
$('.progress-bar-all').css(
'width',
progress + '%'
);
$('#vid-info').html(progress + '%' + ' uploading in progress ' + formatBytes(data.loaded) + ' of ' + formatBytes(data.total));
if (progress == '100') {
$('#vid-info').html('');
document.getElementById("ch_ima").disabled = false;
jQuery('.uploadings').hide();
jQuery('.convert').show();
setTimeout(function() {
jQuery('#progressing').hide();
jQuery('.cn-v').hide();
}, 3000);
}
} else {
jQuery('#progressing-i').show();
jQuery('.cn-i').show();
document.getElementById("ch_img").disabled = true;
var progress = parseInt(data.loaded / data.total * 100, 10);
$('.progress-bar-all-i').css(
'width',
progress + '%'
);
$('.progress-bar-all').html(progress + '%');
$('#ing-info').html('uploading in progress ' + formatBytes(data.loaded) + ' of ' + formatBytes(data.total));
if (progress == '100') {
document.getElementById("ch_img").disabled = false;
setTimeout(function() {
jQuery('#progressing-i').hide();
jQuery('.cn-i').hide();
}, 3000);
$('#ing-info').html('');
}
}
},
add: function(e, data) {
var uploadErrors = [];
// alert(data.originalFiles[0]['size']);
var $image_format = 'jpg|jpeg|jpe|png|gif';
if (section_type == 'video') {
var $audio_format = 'mp4|flv';
}
var $all_formats = $image_format + '|' + $audio_format;
var acceptFileTypes = "(\.|\/)(" + $all_formats + ")$";
acceptFileTypes = new RegExp(acceptFileTypes, "i");
var filetipe = data.originalFiles[0]['type'];
var res = filetipe.split("/");
if (jQuery('#videourl_link').length) {
if (res[0] == 'video') {
uploadErrors.push('Please remove privious video first');
}
}
if (data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
uploadErrors.push('Not an accepted file type');
}
if (data.originalFiles[0]['size'] > 209715200) {
uploadErrors.push('Max allowed size is 200MB ');
}
if (uploadErrors.length > 0) {
alert(uploadErrors.join("\n"));
} else {
jqXHR = data.submit();
}
jQuery('.cncil').click(function(e) {
jqXHR.abort();
jQuery('#ch_ima').prop("disabled", false);
jQuery('#ch_img').prop("disabled", false);
jQuery('#vid-info').html('');
jQuery('#ing-info').html('');
jQuery('.uploading').hide();
jQuery('.progress').hide();
jQuery('.cncil').hide();
});
},
done: function(e, data) {
var obj = jQuery.parseJSON(data.result);
var r = obj.url;
var file_location = obj.file;
var f_mime_type = obj.f_mime_type;
add_more.sort();
if (f_mime_type == 'video') {
var vid_loc = obj.video_file;
}
// console.log(data.result);
if (check_if_image_exist(add_more[0]) != true) {
if (f_mime_type == 'video' && section_type == 'video') {
var extention = vid_loc.split('.').pop();
if (extention == 'mp4' || extention == 'flv') {
jQuery(image_selector + "0").attr("src", r);
jQuery(close_span_id + "0").css("display", "block");
jQuery(uploading_div_id + "-0").css("display", "none");
removeItem = 0;
if (jQuery('#videourl_link').length) {} else {
$(file_upload_section).append('<input type="hidden" id="remove_video" value="' + vid_loc + '">');
$(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="' + section_type + '_image_link-' + removeItem + '" name="' + section_type + '_image_link[]" value="' + r + '">');
$(file_upload_section).append('<input type="hidden" class="remove-item" id="' + section_type + '_image_path-' + removeItem + '" value="' + file_location + '">');
$(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="videourl_link" name="videourl_link" value="' + r + '">');
}
} else {
jQuery(uploading_div_id + "-0").css("display", "none");
jQuery("#video_file").show();
add_more.push("0");
}
} else if (f_mime_type == 'image' && section_type == 'video' && add_more[0] == 0) {
var extention = r.split('.').pop();
if (extention == 'jpg' || extention == 'png' || extention == 'jpeg' || extention == 'gif') {
jQuery(image_selector + "" + add_more[0 + 1]).attr("src", r);
jQuery(close_span_id + "" + add_more[0 + 1]).css("display", "block");
jQuery(uploading_div_id + "-" + add_more[0 + 1]).css("display", "none");
removeItem = add_more[0 + 1];
$(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="' + section_type + '_image_link-' + removeItem + '" name="' + section_type + '_image_link[]" value="' + r + '">');
$(file_upload_section).append('<input type="hidden" class="remove-item" id="' + section_type + '_image_path-' + removeItem + '" value="' + file_location + '">');
} else {
jQuery(uploading_div_id + "-" + add_more[0 + 1]).css("display", "none");
jQuery("#imagev_vfile").show();
}
} else {
if (r == null) {
if (section_type == 'video') {
jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
jQuery('#support_file').show();
} else {
jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
jQuery('#images_file').show();
}
} else {
var extention = f_mime_type.split('.').pop();
if (extention == 'image') {
jQuery(image_selector + "" + add_more[0]).attr("src", r);
jQuery(close_span_id + "" + add_more[0]).css("display", "block");
jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
removeItem = add_more[0];
$(file_upload_section).append('<input type="hidden" class="' + section_type + '_validator" id="' + section_type + '_image_link-' + removeItem + '" name="' + section_type + '_image_link[]" value="' + r + '">');
$(file_upload_section).append('<input type="hidden" class="remove-item" id="' + section_type + '_image_path-' + removeItem + '" value="' + file_location + '">');
} else {
jQuery(uploading_div_id + "-" + add_more[0]).css("display", "none");
jQuery("#images_file").show();
}
}
}
}
var extention = f_mime_type.split('.').pop();
if (section_type == 'channel' && extention != 'image') {} else {
add_more = jQuery.grep(add_more, function(value) {
return value != removeItem;
});
}
if (section_type == 'video') {
for (var k = 0; k < 2; k++) {
var src = jQuery('#vd_image' + k).attr('src');
if (src == 'http://www.example.com/wp-content/themes/example/assets/images/video-placeholder.jpg') {
var onev = 1;
}
}
for (var k = 1; k < 6; k++) {
var src = jQuery('#vd_image' + k).attr('src');
if (src == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
var twov = 1;
}
}
if (onev != '1' && twov != '1') {
document.getElementById("ch_ima").disabled = true;
}
} else {
for (var k = 0; k < 5; k++) {
var src2 = jQuery('#ch_image' + k).attr('src');
if (src2 == 'http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
var hidevcon3 = 1;
}
}
if (hidevcon3 != '1') {
document.getElementById("ch_img").disabled = true;
}
}
jQuery('.uploadings').show();
jQuery('.convert').hide();
add_more.sort();
},
}).prop('disabled', !jQuery.support.fileInput)
.parent().addClass(jQuery.support.fileInput ? undefined : 'disabled');
function check_if_image_exist(check_val) {
for (var x = 0; x < add_more.length; x++) {
if (add_more[x] === check_val) {
return false;
}
}
}
jQuery(".remove-" + section_type + "-image").click(function() {
if (section_type == 'channel') {
document.getElementById("ch_img").disabled = false;
} else if (section_type == 'video') {
document.getElementById("ch_ima").disabled = false;
}
var spanID = jQuery(this).attr("id");
var arr = spanID.split('-')[1];
file_location = jQuery("#" + section_type + "_image_path-" + arr).val();
//alert(file_location);
jQuery.ajax({
type: "POST",
url: wpAjax.ajaxurl,
data: {
action: 'remove_images',
image_loc: file_location
},
beforeSend: function() {
// Handle the beforeSend event
if (image_selector == '#ch_image') {
jQuery("#i-removing-" + arr).css("display", "block");
}
if (image_selector == '#vd_image') {
jQuery("#v-removing-" + arr).css("display", "block");
}
},
success: function(resp) {
if (resp == "200") {
var fl = delete_video_file();
if (image_selector == '#ch_image') {
jQuery("#i-removing-" + arr).css("display", "none");
}
if (image_selector == '#vd_image') {
jQuery("#v-removing-" + arr).css("display", "none");
}
var ext = file_location.split('.').pop();
if (image_selector == '#vd_image' && arr == '0') {
jQuery(image_selector + "" + arr).attr("src", templateUrl + "/assets/images/video-placeholder.jpg");
jQuery(close_span_id + "" + arr).css("display", "none");
jQuery("#" + section_type + "_image_path-" + arr).remove();
jQuery("#" + section_type + "_image_link-" + arr).remove();
if (section_type == 'video' && arr == '0') {
jQuery('#remove_video').remove();
jQuery('#videourl_link').remove();
}
} else {
jQuery(image_selector + "" + arr).attr("src", templateUrl + "/assets/images/placeholder.jpg");
jQuery(close_span_id + "" + arr).css("display", "none");
jQuery("#" + section_type + "_image_path-" + arr).remove();
jQuery("#" + section_type + "_image_link-" + arr).remove();
}
add_more.push(arr);
}
return;
}
});
});
jQuery(".remove-echannel-image").click(function() {
var spanID = jQuery(this).attr("id");
var arr = spanID.split('-')[1];
file_location = jQuery("#" + section_type + "_image_path-" + arr).val();
//alert(file_location);
jQuery(close_span_id + "" + arr).css("display", "none");
jQuery("#i-removing-" + arr).css("display", "none");
jQuery("#channel_image_path-" + arr).remove();
jQuery("#channel_image_link-" + arr).remove();
jQuery("#ch_image" + arr).attr("src", templateUrl + "/assets/images/placeholder.jpg");
return;
});
jQuery(文件上传选择器)。文件上传({
dropZone:$(此),
url:url,
数据类型:“文本”,
async:true,
发送前:函数(xhr){
jQuery('.err').hide();
添加_more.sort();
var file=this.files[0],
fl_type=file.type;
var mim_t=fl_type.split(“/”[0];
//禁用最大文件数
如果(节类型==“视频”){
对于(var k=0;k<2;k++){
var src=jQuery('vd#u image'+k).attr('src');
如果(src=='http://www.example.com/wp-content/themes/example/assets/images/video-placeholder.jpg') {
var onev=1;
}
}
对于(var k=1;k<6;k++){
var src=jQuery('vd#u image'+k).attr('src');
如果(src=='http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
var-twov=1;
}
}
}否则{
对于(var k=0;k<4;k++){
var src2=jQuery('chu image'+k).attr('src');
如果(src2=='http://www.example.com/wp-content/themes/example/assets/images/placeholder.jpg') {
var hidevcon3=1;
}
}
}
如果(onev='1'和&fl_类型!='video/mp4'和&twov!='1'){
警报(“请仅上传视频”);
返回false;
}
//禁用端
如果(节类型=='视频'&添加更多[0]=“0”&mim t==“视频”){
jQuery('#_filechk').val(1);
jQuery(上传分区id+“-0”).css(“显示”、“块”);
}else if(节类型=='视频'&&添加更多[0]=“0”&&mim t==“图像”){
jQuery('#_filechk').val(0);
jQuery(上传分区id+“-”+添加更多[0+1]).css(“显示”、“块”);
}else if(节类型=='视频'&添加更多[0]!=“0”&mim t==“图像”){
jQuery('#_filechk').val(0);
jQuery(上传分区id+“-”+添加更多[0]).css(“显示”、“块”);
}否则{
jQuery('#_filechk').val(0);
jQuery(上传分区id+“-”+添加更多[0]).css(“显示”、“块”);
}
},
progressall:功能(e、数据){
chckp=jQuery('#_filechk').val();
如果(节类型==“视频”){
document.getElementById(“ch_ima”).disabled=true;
jQuery('#progressing').show();
jQuery('.cn-v').show();
var progress=parseInt(data.loaded/data.total*100,10);
$('.progress bar all').css(
“宽度”,
进度+“%”
);
$('#vid info').html(进度+'%'+'正在上载'+formatBytes(data.loaded)+'中的'+formatBytes(data.total));
如果(进度='100'){
$('#vid info').html('');
document.getElementById(“Chu ima”).disabled=false;
jQuery('.uploadings').hide();
jQuery('.convert').show();
setTimeout(函数(){
jQuery('#progressing').hide();
jQuery('.cn-v').hide();
}, 3000);
}
}否则{
jQuery('#progressing-i').show();
jQuery('.cn-i').show();
document.getElementById(“ch_img”).disabled=true;
var progress=parseInt(data.loaded/data.total*100,10);
$('.progress-bar-all-i').css(
“宽度”,
进度+“%”
);
$('.progress bar all').html(进度+'%');
$('#ing info').html('正在上载'+formatBytes(data.loaded)+'of'+formatBytes(data.total));
如果(进度='100'){
document.getElementById(“Chu img”).disabled=false;
setTimeout(函数(){
jQuery('#progressing-i').hide();
jQuery('.cn-i').hide();
}, 3000);
$('#ing info').html('');
}
}
},
添加:功能(e、数据){
var uploadErrors=[];
//警报(data.originalFiles[0]['size']);
var$image|u format='jpg | jpeg | jpe | png | gif';
如果(节类型==“视频”){
变量$audio|U格式='mp4|flv';
}
var$all_format=$image_format+'|'+$audio_format;
var acceptFileTypes=“(\。\ \ \/)(“+$all\u formats+”)$”;
acceptFileTypes=新的RegExp(acceptFileTypes,“i”);
var filetipe=data.originalFiles[0]['type'];
var res=filetipe.split(“/”);
if(jQuery('#videourl_link').length){
如果(res[0]=“视频”){
上传错误。推送(“请先删除私密视频”);
}
}
if(data.originalFiles[0]['type'].length&!acceptFileTypes.test(data.originalFiles[0]['type'])){
uploadErrors.push('不是可接受的文件类型');
}
if(数据原始文件[0]['size']>209715200){
上传错误。推送('允许的最大大小为200MB');
}
我