Can I use the HTML5 upload attribute for HTML forms?

HTML5 introduces the great ability to mark links <a>

as download endpoints by simply adding an attribute download

to the tag <a>

(see description) .

Can you do the same for HTML forms?

Here's a simple use case: I have a form that asks the user for some details, and after the user submits the form, the server has to return a file according to those details.


source to share

3 answers

It's impossible. According to the specification, the "load" attribute is specified for a and region only .



No, form

it has no attributedownload

, so it is not possible to set the exact behavior with form


You can set the name of the output file though the message by setting the Content-Disposition

HTTP header:

Content-Disposition: attachment; filename="yourPicture.png"




Yes, after sending the data, you can return the file in pdf format or otherwise. Using the title function

//create pdf with details
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');


But this is not possible with download attribute



All Articles