How do I prompt for a file without uploading it in HTML?

Use an <input type="file">. The browser will prompt the user to choose a file locally; your page can’t access it until they select it.

Solution:

<label for="file">Choose a file:</label>
<input id="file" name="file" type="file">

To submit it to a server:

<form action="/upload" method="post" enctype="multipart/form-data">
 <input name="file" type="file" required>
 <button type="submit">Upload</button>
</form>

If you mean “choose a file but don’t upload it,” omit the form submission (or handle the change event in JavaScript). You can’t open the file picker automatically; it must be triggered by a user action.

4 Views