mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
665 B
27 lines
665 B
4 years ago
|
<script>
|
||
|
let files;
|
||
|
|
||
|
$: if (files) {
|
||
|
// Note that `files` is of type `FileList`, not an Array:
|
||
|
// https://developer.mozilla.org/en-US/docs/Web/API/FileList
|
||
|
console.log(files);
|
||
|
|
||
|
for (const file of files) {
|
||
|
console.log(`${file.name}: ${file.size} bytes`);
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<label for="avatar">Upload a picture:</label>
|
||
1 year ago
|
<input accept="image/png, image/jpeg" bind:files id="avatar" name="avatar" type="file" />
|
||
4 years ago
|
|
||
|
<label for="many">Upload multiple files of any type:</label>
|
||
1 year ago
|
<input bind:files id="many" multiple type="file" />
|
||
4 years ago
|
|
||
|
{#if files}
|
||
|
<h2>Selected files:</h2>
|
||
|
{#each Array.from(files) as file}
|
||
1 year ago
|
<p>{file.name} ({file.size} bytes)</p>
|
||
4 years ago
|
{/each}
|
||
|
{/if}
|