input+type=file同时支持文件和文件夹

2023-06-23 14:17:08 浏览数 (2)

1没有知识的旅游者是一只没有翅膀的鸟。——萨阿迪

使用的dropzone库,你可以将任意类型的文件拖拽进去上传,如果是目录,则会获取目录内的文件

https://github.com/dropzone/dropzone

代码如下:

代码语言:javascript复制
<link
  rel="stylesheet"
  href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css"
  type="text/css"
/>

<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>

<div class="my-dropzone dz-clickable" style="
    display: block;
    width: 100px;
    height: 100px;
    background: greenyellow;
"></div>

<script>
  // Dropzone has been added as a global variable.
  const dropzone = new Dropzone("div.my-dropzone", { url: "/file/post" });
   console.log({dropzone})
</script>

效果:

// Dropzone has been added as a global variable. const dropzone = new Dropzone("div.my-dropzone", { url: "/file/post" }); console.log({dropzone})

0 人点赞