后端文件阵列结构不良

时间:2019-04-05 15:05:12

标签: php jquery dropzone.js

嘿,在这里使用dropzone来将一些文件上传到我的服务器。目前,我将其配置为在单击“上传”按钮之前不上传,这样我就可以管理和重新排列队列中的文件。当我上传它们时,在我的后端,我得到了文件的数组结构:

$_FILES['file']['name'][0] == "my-first-file-name.xls"

$_FILES['file']['name'][1] == "my-second-file-name.sml"

$_FILES['file']['tmp_name'][0] == "my-first-file-tmp-name"

$_FILES['file']['tmp_name'][1] == "my-second-file-tmp-name"

我认为与我之前在其他技术中使用的一样,正确的是:

$_FILES['file'][0]['name']

$_FILES['file'][0]['tmp_name']

$_FILES['file'][1]['name']

$_FILES['file'][1]['tmp_name']

我在做什么错?

将paramName:选项更改为“ files []”无效。

javascript

$(document).ready(function() {
    $("#button").click(function (e) {
        e.preventDefault()
        var myDropzone = Dropzone.forElement(".dropzone");
        myDropzone.processQueue()
    });
})

Dropzone.options.myAwesomeDropzone = { 
paramName: "file", 
maxFilesize: 5, 
uploadMultiple: true, 
maxFiles: 10, 
acceptedFiles: ".xls, .xml, .xlsx", 
addRemoveLinks: true, 
autoProcessQueue: false, 
parallelUploads: 10, 
dictDefaultMessage: "<strong>Arraste os arquivos aqui ou clique para selecionálos. </strong>", 
dictInvalidFileType: "Este tipo de arquivo não é permitido.", 
dictRemoveFile: "Remover"
};

html

<form action="/files/fileImport" class="dropzone" id="myAwesomeDropzone">   
</form>

1 个答案:

答案 0 :(得分:0)

是的,没错,Dropzone具有强大的上传多个文件的功能,因此您可以获得一系列名称和tmp_names。您只需要相应地编写代码即可,即循环遍历数组并将其保存在后端中。如果您不想要该功能,则应相应地更改设置

Dropzone.options.myAwesomeDropzone = { 
    paramName: "file", 
    maxFilesize: 5, 
    uploadMultiple: true, // change this to false
    maxFiles: 10, // here change this to 1
    acceptedFiles: ".xls, .xml, .xlsx", 
    addRemoveLinks: true, 
    autoProcessQueue: false, 
    parallelUploads: 10, 
    dictDefaultMessage: "<strong>Arraste os arquivos aqui ou clique para selecionálos. </strong>", 
    dictInvalidFileType: "Este tipo de arquivo não é permitido.", 
    dictRemoveFile: "Remover"
};