2
votes

I can send files from the browser to the server using drag'n'drop and this code simply works fine:

        var temp = new FormData();
        temp.append("file_content",e.originalEvent.dataTransfer.files[0]);
        //Ajax POST here...

Then I make a POST request (Ajax) to send that file to PHP and PHP can manipulate that file using $_FILES[file_content]. Easy.

My problem is that sometimes the user drops a folder and I already can manipulate the files inside that folder with JS in order to send them via Ajax. My problem is that PHP cant manipulate the $_FILE anymore, it is empty. My code:

var reader = entry.createReader();

reader.readEntries(function(entries) {
    
    entries.forEach(function(dir,key) {
        
        if (dir.isFile) {

            var temp = new FormData();
            temp.append("file_content",dir);

            //Ajax POST here...
            
        }
    
    });
    
}); 

So I need someway to convert dir (which is of type FileEntry) to type File (e.originalEvent.dataTransfer.files[0]). How can I do this?