Recently, I have been developing a web surface page that can upload images to the server. Here I will share with you the requirements and implementation ideas as well as the ajax source code. Friends who are interested in ajax can refer to the Ajax implementation with Spring File uploadfunction!
Due to project needs, develop a web form page that can upload images to the server.
1. Requirements
Web form page, you can upload pictures and other text information through the form.
2. The process of uploading pictures
I have never done this type of page before, so I can query the information. It is found that a common practice is to first upload the image to a file directory on the server side, and the server returns the storage path of the image to the front desk; then, the front desk submits the image storage path and other form information to the server, and all form information is stored in the database.
3. Method
Due to project needs, I will introduce two methods of image uploading here. The first one is to use ajax to directly upload an image. Upload; the second is to first cut the image into smaller files at the front desk, and then use ajax to upload the images to the server respectively, and the server will splice the files. (Method 2 is suitable for uploading larger files) Below I will introduce the two methods respectively.
Method 1: Directly upload the
1 html page
<pre name="code" class="html"><!DOCTYPE html> <head></head> <body> <form id="uploadForm" action="/PicSubmit/form" method="post" enctype="multipart/form-data" onsubmit="return submit_check()" class="bootstrap-frm" >
<input id = "sid" type = "text" name="name" />
<pre name="code" class="html"><input id = "fileImage" type = "file" name="filename" />
<input id = "addressid" type = "hidden" name="address" />
<input id="ajaxsub" type="button" class="button" value="上传图片" onclick="fileUpload()<span style="font-family: Arial, Helvetica, sans-serif;">" /> </span>
<input type="submit" class="button" value="提交表单" /> <input type="reset" class="button" value="重置表单" />