Dropzone正常形式问题

时间:2019-01-03 10:17:47

标签: php laravel 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>

1 个答案:

答案 0 :(得分:1)

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

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