首页 > 解决方案 > Dropzone范式问题

问题描述

嘿伙计们,我正在尝试以正常形式使用 dropezone,但是当我提交时似乎只对图片收费

这是我的html代码:

<form role="form" action="{{route('handleAddNewTrip')}}" class="dropzone" id="mydropzone" method="post" enctype="multipart/form-data">
    {{csrf_field()}}
    <div class="col-md-6">
       <div class="form-group">
           <label>Titre de voyage</label>
           <div id="dropzonePreview"></div>
           <button type="submit" name="save" class="btn btn-primary pull-right">Ajouter</button>
           <button type="reset" class="btn btn-default pull-right">Annuler</button>
       </div>
   </div>
</form>

这是我的js代码

<script>
    //  Bind the event handler to the "submit" JavaScript event
    $('form').submit(function(e) {
        myDropzone.processQueue();
        Dropzone.options.mydropzone = {
           //url does not has to be written 
           //if we have wrote action in the form 
           //tag but i have mentioned here just for convenience sake 
           url: '{{route('handleAddNewTrip ')}}',
           addRemoveLinks: true,
           autoProcessQueue: false, // this is important as you dont want form to be submitted unless you have clicked the submit button
           autoDiscover: false,
           paramName: 'pic', // this is optional Like this one will get accessed in php by writing $_FILE['pic'] // if you dont specify it then bydefault it taked 'file' as paramName eg: $_FILE['file'] 
           previewsContainer: '#dropzonePreview', // we specify on which div id we must show the files
           clickable: false, // this tells that the dropzone will not be clickable . we have to do it because v dont want the whole form to be clickable 
           accept: function(file, done) {
           console.log("uploaded");
           done();
        },
        error: function(file, msg) {
           alert(msg);
        },
   };
</script>

标签: phplaraveldropzone

解决方案


可能是这样:尝试将“acceptedFiles”添加到您的 dropzone 选项中,它需要一系列接受的扩展名。它对我有用。

文档:https ://www.dropzonejs.com/#config-acceptedFiles


推荐阅读