Recently I am developing a web surface page that can upload pictures to the server. Let me share the requirements and implementation ideas with you. Friends who need it can refer to it
Due to the needs of the project, I have developed a web page that can upload pictures to the server. web form page.
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 have to 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="重置表单" />