Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-25-2020, 06:22 AM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Drag & Drop Upload Problem

I am trying implement a drag and drop uploader in the newattachment template. I have used all variables in the default template, and everything is looking right, the hover is good when I hover a file over it. but when I release the mouse on the box it does not upload the file.

I have included all code I felt relevant that could be causing a problem. I can not figure out what the issue is.

*keep in mind this is a stripped code*

the form:
HTML Code:
<form enctype="multipart/form-data" action="newattachment.php?do=manageattach&amp;p=$postid" id="manageAttachmentForm" name="newattachment" method="post">
<input type="hidden" name="s" value="$session[sessionhash]" />
<input type="hidden" name="securitytoken" value="$bbuserinfo[securitytoken]" />
<input type="hidden" name="do" value="manageattach" />
<input type="hidden" name="t" value="$threadid" />
<input type="hidden" name="f" value="$forumid" />
<input type="hidden" name="p" value="$postid" />
<input type="hidden" name="poststarttime" value="$poststarttime" />
<input type="hidden" name="editpost" value="$editpost" />
<input type="hidden" name="posthash" value="$posthash" />
The drop zone:
HTML Code:
<div class="upload-container" id="uploadholder">
  <input type="hidden" name="MAX_FILE_SIZE" value="$inimaxattach">
  <div class="attachment-form">
    <div class="form-group"><label for="fileInput">Select files to upload</label></div>
    <input type="file" name="attachment[]" id="fileInput" multiple />
  </div>
  <div class="js-only">
  <p class="help-block prompt">
    <span class="banner-text">Drag files here to upload</span>
    <br>or<br>
    <button class="btn btn-lg btn-default" data-action="choose-files">Select Files</button>
  </p>
  <div id="uploadStatus" style="display: none;"><i class="fal fa-spinner fa-spin"></i> Uploading files. Please wait.</div>
  <p class="help-block prompt">Maximum upload file size: 20 MB.<br><a href="#" data-toggle="modal" data-target="#uploadInfo">What can I upload?</a></p>
  </div>
</div>
The Submit button:
HTML Code:
<input type="submit" id="btnUpload" class="btn btn-lg btn-block btn-primary" name="upload" value="$vbphrase[upload]" onclick="return verify_upload(this.form);">
</form>
The Js:
Code:
<script>
$('form#manageAttachmentForm #fileInput').change( function(event) {
	$('<input />').attr('type', 'hidden')
              .attr('name', 'upload')
              .attr('value', '1')
              .appendTo('#manageAttachmentForm');
	$('form#manageAttachmentForm #uploadStatus').show();
	$('form#manageAttachmentForm').submit();
});

$('#uploadholder').on({
	'dragover dragenter': function(e) {
		$('#uploadholder .banner-text').text("Drop files here");
		$(this).addClass("holder-hover");
		e.preventDefault();
		e.stopPropagation();
	},
	'dragleave': function(e) {
		$('#uploadholder .banner-text').text("Drag files here to upload");
		$(this).removeClass("holder-hover");
	},
	'drop': function(e) {
		$('#uploadholder .banner-text').text("Drag files here to upload");
		$(this).removeClass("holder-hover");
		var dataTransfer =  e.originalEvent.dataTransfer;
		if( dataTransfer && dataTransfer.files.length) {
			fileInput.files = dataTransfer.files;
			e.preventDefault();
			e.stopPropagation();
		}
	}
});
</script>
Also, I can upload attachments manually just fine. But I cant get the drag and drop portion to work.

--------------- Added [DATE]1590415855[/DATE] at [TIME]1590415855[/TIME] ---------------

edited the code to better target the problem

I think the problem may lay in this bit of Js, but evrything looks correct to me.
Code:
'drop': function(e) {
  $('#uploadholder .banner-text').text("Drag files here to upload");
  $(this).removeClass("holder-hover");
  var dataTransfer =  e.originalEvent.dataTransfer;
  if( dataTransfer && dataTransfer.files.length) {
    fileInput.files = dataTransfer.files;
    e.preventDefault();
    e.stopPropagation();
  }
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:18 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03838 seconds
  • Memory Usage 2,164KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (3)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete