Uploadify's Broken Thoughts

Source: Internet
Author: User

Uploadify is a jquery plugin used to implement file upload functionality.

Generally will buy a HTML5 version of the.

Html

<input id= "custom_file_upload" type= "file" name= "Filedata"/>

Js

The key is to set the path correctly
//Always initiate a request: Http://localhost:8080/jyxt/img/uploadify-cancel.png, do not know where to start?
function Inituploadimge () {$ (' #custom_file_upload1 '). Uploadify ({' swf ': path_t+ ' js/uploadify.swf ',
Spooler url ' uploader ': path_t+ ' manage/fileupload/', ' method ': ' Post ', ' use_query_string ': True, ' Post_params ': {"Hello": encodeURI ("Hello, I Am", "utf-8"), "BaseURL": "User Files/images/linkimages/"}, ' Cancelimage ': path_t+ ' images/cancel.png ', ' buttontext ': ' Browse ', ' buttonimg ': path_t+ ' images/sel.png ', ' Queueid ': ' custom-queue1 ', ' filetypeexts ': ' *.jpg;*.gif;*.png; ', ' filetypedesc ': ' Picture file ', ' removecompleted ': true, ' onSelect Once ': function (event,data) {$ (' #custom-queue1 '). Text (' File crosses! '); }, ' Onuploadsuccess ': function (file, data, response) {$ (' #custom-queue1 '). Text (' upload succeeded '); $ (' #picUrl '). attr ("value", data); } });}

Controller

Stored path settings are more troublesome
//1, Savepath How to set the base path? BaseURL is the path to pass, relative to the webcontent.
//2, when saved, will be saved to Tomcat, should be saved in jyxt ah?
3, Savefile.getabsolute () can get the path of file storage.
4, Request.getservletpath () is the value of uploader
@RequestMapping (value = "/manage/fileupload/", method = requestmethod.post) public void FileUpload (httpservletrequest Request,httpservletresponse response) throws Exception {//set path String baseurl=request.getparameter ("BaseURL"); The path has a problem String Savepath = Request.getsession (). Getservletcontext (). Getrealpath ("") + "/" +BASEURL; Diskfileitemfactory FAC = new Diskfileitemfactory (); Servletfileupload upload = new Servletfileupload (FAC); String filename= ""; File F1 = new file (Savepath); if (!f1.exists ()) {f1.mkdirs (); } list<fileitem> fileList = null; FileList = (list<fileitem>) upload.parserequest (request); Iterator<fileitem> it = Filelist.iterator (); String name = ""; String extname = ""; while (It.hasnext ()) {Fileitem item = It.next (); if (!item.isformfield ()) {name = Item.getname (); if (name = = NULL | | Name.trim (). Equals ("")) {continue; } if (Name.lastindexof (".") >= 0) {extname = name.substring (Name.lastindexof (".")); } object[] test = {"GIF", "png", "JPG", "Doc", "docx", "xls", "xlsx", "ppt", "pptx", "PTF", "rar", "Zip", ""}; if (! Arrayutils.contains (test, extname.tolowercase (). substring (1))) {continue; } file file = null; do {name=dateutil.getnowdatestring (); Filename=savepath + name + extname; File = new file (filename); } while (File.exists ()); File SaveFile = new file (filename); try {item.write (saveFile); } catch (Exception e) {e.printstacktrace (); }}} response.getwriter (). Print (Request.getcontextpath () + "/userfiles/images/linkimages/" +name+extname);

The above code is available. However, because the uploadify version is different, the file path may be problematic. Just take this to record some key issues.

Uploadify's Broken Thoughts

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.