Dropzone多个文件上传不适用于Excel文件

时间:2019-06-18 10:09:24

标签: javascript php jquery laravel dropzone.js

我在Dropzone和Laravel 5.7中遇到了一个问题。我目前正在将Excel文件通过dropzone上传到。但是它不能正常工作。例如,如果我添加10个文件,则在我的数据库中有10个具有不同文件名的条目,但在“文件存储”文件夹中没有10个文件,它不同于6,7,8个文件。我正在为upload_max_filesizemax_file_uploads更改php.ini文件。这是我的代码段。 我的Js代码

<script type="text/javascript">
    Dropzone.options.dropzone =
        {
            parallelUploads: 1, // Uploads one (1) file at a time, change to whatever you like.
            autoProcessQueue: true,
            uploadMultiple: true,
            maxFiles: 100,
            maxFilesize: 3,
            autoQueue: true,
            renameFile: function (file) {
                var dt = new Date();
                var time = dt.getTime();
                return time + file.name;
            },
            addRemoveLinks: true,
            timeout: 50000,
            removedfile: function (file)
            {
                var name = file.upload.filename;
                $.ajax({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    type: 'POST',
                    url: '{{ url("admin.pos.deleteexcel") }}',
                    data: {filename: name},
                    success: function (data) {
                        console.log("File has been successfully removed!!");
                    },
                    error: function (e) {
                        console.log(e);
                    }});
                var fileRef;
                return (fileRef = file.previewElement) != null ?
                        fileRef.parentNode.removeChild(file.previewElement) : void 0;
            },
            success: function (file, response)
            {
                console.log(response);
            },
            error: function (file, response)
            {
                return false;
            }
        };
</script>

我的表格是

{!! Form::open(['method'=>'POST', 'action'=>'backend\ExcelController@multipleExcelStore', 'files'=>true, 'id' => 'dropzone_form', 'class'=>'dropzone needsclick dz-clickable']) !!}
        <div class="dz-message needsclick">
            <div class="search-block">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="upload_container">
                            <div class="upbtn_block_1">
                                Drag &amp; drop Files Here
                            </div><!--/upbtn_block_1 -->
                            <div class="up_text_block">Or</div>
                            <div class="upload_btn"><span>Browse File</span></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {!! Form::close() !!}

我的控制器代码

public function multipleExcelStore(Request $request) {
    $input = [];
    $imageName = Carbon::now()->format('Y') . '/' . Carbon::now()->format('m') . '/' . uniqid() . '_' . time() . '.' . $request->file('file')->getClientOriginalExtension();
    $destinationPath = Config::get('constants.PO_MULTILE_ATTACHEMNT') . '/';
    Helper::uploadFile($request->file('file'), null, $destinationPath, $imageName);
    $input['attachment'] = Config::get('constants.PO_MULTILE_ATTACHEMNT') . '/' . $imageName;
    $input['process_user_id'] = Auth::guard('admin')->user()->id;
    $input['process_ip'] = $request->ip();
    $input['name'] = $request->file('file')->getClientOriginalName();
    PosExcel::create($input);
    return response()->json(['success' => $imageName]);
}

我用google搜索,但没有成功返回。 谢谢

1 个答案:

答案 0 :(得分:0)

您是否尝试删除

autoProcessQueue: true,
            uploadMultiple: true,

我有另一个上载多个项目的项目,不需要在javascript中使用该参数,也可能是队列问题,请尝试并告诉我们:)

祝你好运