Input file with pre-selected file

0

I have the code below that at the click of a button, open the windows explorer window to select a file and then send a POST to a .php file.

The file I want to send to POST, is already on the server and I have the source path. How do I make this code send the POST with the file I need without opening windows?

Import: function() {
    var _this = this;
    var importButton = this._controlPanel.ProjectPages.self.querySelector('.import');
    importButton.addEventListener('click', function() {
        if (!_this._triggerImport) {
            _this._triggerImport = true;
            var inputFile = document.createElement('input');
            inputFile.setAttribute("type", "file");
            inputFile.setAttribute("name", 'data');
            inputFile.style.display = 'none';
            document.body.appendChild(inputFile);
            inputFile.addEventListener('change', function () {
                if (inputFile.files && inputFile.files[0]) {
                    var nameFile = inputFile.files[0].name;
                    var form = new FormData();
                    form.append('data', inputFile.files[0]);
                    form.append('name_file', nameFile);
                    _this.ajax(form, 'import', function (data) {
                        var datas = _this._prepareContentPagesToSave('no-storage');

                        _this._loadProject(data, 'load');
                        document.body.removeChild(inputFile);

                        builder.setStep(function () {
                            _this._loadProject(datas, 'import');
                        });
                    });
                }
            });
            inputFile.click();
            setTimeout(function(){
                _this._triggerImport = false;
            },2000);
        }
    });

}
    
asked by anonymous 30.08.2018 / 03:25

0 answers