A little summary of uploading files

Source: Internet
Author: User

Because recently in the function of file upload, so afraid of forgetting to summarize a little bit

1, upload the file best use commons-file-upload this plugin (seemingly support large file upload)

2, questions about multi-file selection

By default, multi-select files are forbidden, and even if you use CTRL and SHIFT, you cannot select multiple files.

At this point we only need to add multiple= "multiple" on the file tag, it seems that this property is H5 property, after the addition of the file can be selected by CTRL or SHIFT to select multiple files

<input type= "file" name= "Files" multiple= "multiple" id= "UploadFile"/>

3, about the use of the file upload function in the page, resulting in the inability to use Ajax situations

because file uploads are transmitted in the form of a binary stream, the XMLHTTP object that is one of the key objects of Ajax transmits a stream of characters in XML format , resulting in the inability to use Ajax to commit files asynchronously But we can implement the Ajax function in disguise by some means, we can set the form's submission target to the IFRAME through the IFRAME, when we submit the form, we will first submit the image data to the IFRAME and submit it to the background in this hidden iframe.

This time will cause "page no refresh" Illusion!

It may be troublesome when we write manually, but the easiest way is to use the form plugin in Easyui, we just need to write the form in the normal way, then use Easyui to encapsulate the table, and then set the corresponding submission address!

But the bottom of the Easyui is also an iframe to "asynchronously" submit files, but this is the easiest way to do the project!

4, about the file upload save address problem

In general, we may save the uploaded file in a folder in the project directory, but there is a big risk that when we redeploy the project, the new project will overwrite the project, that is, when the project is deployed, the previously uploaded files will be emptied.

In general, we may be the project directory is nothing more than request.getsession (). Getservletcontext (). Getrealpath ("/") and other means,

Sometimes we test in the main method and get the project path to D://project/xxx

However, when the project is running on a server such as Tomcat, this address is inexplicably "changed" into a Tomcat address, which is actually very simple to explain, when we use main at run time, this time just run the project actually save the directory, When we deploy a project on a server such as Tomcat

the project that we access through the address is running the project that is deployed on Tomcat , so it causes the project's path to be inconsistent with the project path in the main method at the time of deployment

So when we deploy a new project, we must do a good job of backup operations, so as not to overwrite the previous file, the simplest way is to upload the file after the completion of the quartz, such as the timing of the time frame, such as how often the file copied to the other directory of the hard disk, so that the tragedy can avoid the occurrence!

5, on the different platform address is not common problem

The address we want to access a folder on Windows is typically the D:\ software \program\ppt (d:/software/program/ppt on Windows also recognizes)

But in Linux UNIX systems, the address is d:/software/program/ppt

If you put d:\ software \program\ppt such an address on Linux, it will not be recognized.

The solution is that we can use the File.separator attribute to solve:

"D" +file.separator+ "Project" +file.separator+ "xxx"

The system will automatically generate different slashes based on the operating system, so you can avoid the path written on windows that is not recognized on Linux!

These are only the problems encountered in daily life, and "solution", can only relieve pain, to cure, but also to study and study seriously!

If there is something wrong with the above, I hope you can point it out!

A little summary of uploading files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.