Swfupfile uploaded with multiple images

Source: Internet
Author: User

 

Not to mention nonsense ,:

Uploaded files are automatically added to the database.

Usage:

Add in the header of the page to be uploaded (CSS, images, and JS should also be copied in)

<Link href = "css.css" rel = "stylesheet" type = "text/CSS"/> <SCRIPT type = "text/JavaScript" src = "swfupload/swfupload. JS "> </SCRIPT> <SCRIPT type =" text/JavaScript "src =" JS/swfupload. queue. JS "> </SCRIPT> <SCRIPT type =" text/JavaScript "src =" JS/fileprogress. JS "> </SCRIPT> <SCRIPT type =" text/JavaScript "src =" JS/filegroupprogress. JS "> </SCRIPT> <SCRIPT type =" text/JavaScript "src =" JS/handlers. JS "> </SCRIPT> <SCRIPT type =" text/JavaScript "> var swfu; window. onload = function () {var settings = {flash_url: "swfupload/swfupload.swf", upload_url: "imgupload. ashx ", // data submission and processing page file_size_limit:" 2 MB ", // size limit file_types :"*. jpg ", // file_types_description:" JPG images ", // JPG file file_upload_limit: 100, limit: 0, custom_settings: {progresstarget:" divprogresscontainer ", progressgrouptarget: "divprogressgroup", // progress object container_css: "progressobj", progress: "iconormal", icowaiting_css: "icowaiting", progress: "icoupload", fname_css: "fle ftt ", state_div_css: "statebarsmalldiv", state_bar_css: "statebar", percent_css: "FTT", href_delete_css: "FTT ", // elements declared starting with "CNT _" */s_cnt_progress: "cnt_progress", s_cnt_span_text: "FLE", s_cnt_progress_statebar: "cnt_progress_statebar ", s_cnt_progress_percent: "cnt_progress_percent", progress: "progress", s_cnt_progress_size: "cnt_progress_size"}, debug: false, // button settings button_image_url: "images/progress", button_width: "65", button_height: "29", button_placeholder_id: "spanbuttonplaceholder", button_text: '<SPAN class = "thefont"> Upload File </span>', button_text_style :". thefont {font-size: 12; color: #0068b7;} ", button_text_left_padding: 12, button_text_top_padding: 3, // The event handler functions are defined in handlers. JS Plugin: filequeued, Handler: filequeueerror, upload_start_handler: uploadstart, Handler: uploadprogress, Handler: uploaderror, Handler: uploadsuccess, Handler: uploadcomplete, Handler: filealodigcomplete }; swfu = new swfupload (settings) ;}; </SCRIPT>

 

Put the following code in the specific place to upload

 

<span id="spanButtonPlaceHolder"></span><div id="divprogresscontainer">  </div> <div id="divprogressGroup"> </div>

 

Add a general processing program (imgupload. ashx) to store uploaded images to the database.

<% @ Webhandler Language = "C #" class = "imgupload" %> using system; using system. collections. generic; using system. web; using system. io; public class imgupload: ihttphandler {public void processrequest (httpcontext context) {If (context. request. cookies ["user"] = NULL) {jiangs_tools.show_msg ("Please log on again");} Try {httppostedfile file; For (INT I = 0; I <context. request. files. count; ++ I) {file = context. request. files [I]; If (file = NULL | file. contentlength = 0 | string. isnullorempty (file. filename) continue; file. saveas (httpcontext. current. server. mappath ("uploadfile/" + path. getfilename (file. filename); // Save the image string newname = sjname () + path. getextension (file. filename); // generate a new name file. move (context. server. mappath ("uploadfile/" + path. getfilename (file. filename), context. server. mappath ("uploadfile/" + newname); // rename jiang_db newdb = new jiang_db (); newdb. open (); newdb. execsql (string. format ("insert into [img] ([name], [img], [member_id]) values ('{0}', '{1 }', '{2}') ", // saved to the database path. getfilenamewithoutextension (file. filename), "/uploadfile/" + newname, context. request. cookies ["user"] ["ID"]); newdb. close (); // file. appendalltext (context. server. mappath ("filename.txt"), file. filename + "new name:" + newname + environment. newline) ;}} catch (exception ex) {context. response. status Code = 500; context. response. write (ex. message); context. response. end ();} finally {context. response. end () ;}} public bool isreusable {get {return false ;}} /// <summary> /// generate a prompt name /// </Summary> /// <returns> </returns> Public String sjname () {string SJ = NULL; SJ = datetime. now. year. tostring () + datetime. now. month. tostring () + datetime. now. day. tostring () + datetime. now. timeofday. hours. tostring () + datetime. now. timeofday. minutes. tostring () + datetime. now. timeofday. milliseconds. tostring (); Return SJ ;}}

 

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.