如何将文件附加到输入类型文件?

时间:2019-05-09 10:27:53

标签: javascript php jquery laravel

我有一个表格,用户可以在其中编写标题并从PC上载文件。 我的JS脚本会生成一个Excel文件并将其保存到PC。如何将JS生成的文件附加到文件输入中?例如,我按tableToExcel,文件将自动附加或附加到文件输入中。

<div class="form-group">
  <label for="title">Title:</label>
  <input id="textthree" type="text" class="form-control" name="title">
</div>
<div class="form-group col-md-3">
  <input id="four" type="file" class="form-control" name="document" accept="application/vnd.ms-excel">
</div>
<div class="form-group col-md-2">
  <button type="submit" class="btn btn-sm btn-outline-success">Send email</button>
</div>
var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,',
    var link = document.createElement("a");

  link.download = "File.xls";
  link.href = uri + base64(format(template, ctx));

  const blob = new Blob([format(template, ctx)], {
    type: "application/vnd.ms-excel;charset=utf-8"
  });

  saveAs(blob, "File.xls");
}
})();

或者我如何将javascript生成的blob文件传递给下面的php函数以保存在laravel文件存储中?

 var link = document.createElement("a");
                    link.download = "file.xls";
                    link.href = uri + base64(format(template, ctx));
                    const blob = new Blob([format(template, ctx)], {
                        type: "application/vnd.ms-excel;charset=utf-8"
                    });
                     <?php use Illuminate\Support\Facades\Storage;
                     Storage::disk('local')->put('excel.xls', "blob") ?>

                    saveAs(blob, "file.xls");
                  //  var storagePath = "{!! storage_path() !!}";
                }
            })();

0 个答案:

没有答案