How to upload file in html? - html

How to upload a file in simple html? What all tags must be used?
<form action="/action_page.php">
<input name="pic" accept="image/*">
<input type="submit">
</form>

<form action="/action_page.php" method="post" enctype="multipart/form-data">
<input type="file" name="pic" id="image">
<input type="submit" name="submit">
</form>
you need a form with method POST & enctype multipart/form-data
you need a input type file to add your file
you need a button to submit. (you can submit without it too... using jQuery)

You need to do 2 changes.
<form action="/action_page.php" method="post" enctype="multipart/form-data">
Secondly, the field tag
<input type="file" name="pic" accept="image/*">

Related

How can I use a file input and text input all in one form

How can I use a file input and text input all in one form
Thanks in anticipation
I guess you must be pretty new to html
here is a sample
<form action="upload.php" method="post" enctype="multipart/form-data">
<label> Name </label>
<input type="text" name="name">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>

Simple form data not working

I'm trying to upload an image and send it over to a server using a very basic form in HTML. Here is my code:
<form action="/api/addCategory" enctype="multipart/form-data" method="post">
<input type="hidden" name="name" value="test">
<input type="file" name="file" />
<input type="submit" value="Submit">
</form>
However when I click the button nothing happens (the server doesn't get any requests). The strange thing is I'm using an almost identical version of this code somewhere else in my project and it's working completely fine. What am I missing here?
Try like this ! Use any server side language like php.
<form action="/api/addCategory" enctype="multipart/form-data" method="post">
<input type="hidden" name="name" value="test">
<input type="file" name="file" />
<input type="submit" value="Submit">
<input class="fileattach" type="file" placeholder="upload" name="attachment" required><br></input>
</form>

How can I make a submit button using html for several form action?

Can I use just a single <input type="submit" value="submit"> but for several form actions ...
Say if I type
<form id="form1" action="action1.py" method="get">
<input type="text" name="name">
</form>
<form id="form2" action="action2.py" method="get">
<input type="text" name="random">
<form>
then I want to use just a single <input type="submit" value="submit" or if there is another way to do it? Can anyone please explain me how to do it?

Submit form as "multipart/form-data" but content-type is “application/x-www-form-urlencoded” on the server

I'm trying to submit a form that includes a file, I'm using enctype="multipart/form-data" but the request content-type is sent as “application/x-www-form-urlencoded”, this is the part of the code:
<div id="uploadTest" data-role="page" align="right">
<form id="uploadTestForm" action="/Upload" method="POST" enctype="multipart/form-data">
<input type="text" name="text" autofocus required>
<input id="ImageFile" type="file" data-clear-btn="false" name="image" accept="image/*" capture>
<button type="submit" data-theme="a">Upload</button>
</form>
</div>
This is a part of my HTML5 application that need to upload the file.
There is no JS code that run on submitting the form.
May you please help me find why I cannot submit the form as "multipart/form-data"?
I was able to find out what was the problem.
I just added data-ajax="false" to the form and now it is working.

How to filter xls,xlsx and csv extension files in browse button of form tag of html?

how to filter excel,csv files while browsing.
<form action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi"
enctype="multipart/form-data" method="post">
<p>
`enter code here`Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>
Using the attribute "accept" with .xls, .xlsx, .csv. I guess.