PHP Multiple File Array

前端 未结 6 1205
陌清茗
陌清茗 2020-12-03 09:29

I have the following code which works and uploads but it will not cycle through the array to upload every file, just the first file.

6条回答
  •  再見小時候
    2020-12-03 09:52

    Try with this code for multifile upload

    
     
    
    

    In PHP

    if(count($_FILES['uploads']['filesToUpload'])) {
    foreach ($_FILES['uploads']['filesToUpload'] as $file) {
    
        //do your upload stuff here
        echo $file;
    
    }
    }
    

    To show the file name using javascript

    //get the input and UL list
    var input = document.getElementById('filesToUpload');
    var list = document.getElementById('fileList');
    
    //empty list for now...
    while (list.hasChildNodes()) {
    list.removeChild(ul.firstChild);
    }
    
    //for every file...
    for (var x = 0; x < input.files.length; x++) {
    //add to list
    var li = document.createElement('li');
    li.innerHTML = 'File ' + (x + 1) + ':  ' + input.files[x].name;
    list.append(li);
    }
    

提交回复
热议问题