vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Drag & Drop Upload Problem (https://vborg.vbsupport.ru/showthread.php?t=328053)

Dr.CustUmz 05-25-2020 06:22 AM

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();
  }
}



All times are GMT. The time now is 10:10 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01212 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (3)bbcode_html_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete