Previously improved several file uploads, those are good. Today, small series to lead you to experience a new upload method, and the use of Flash plug-ins to achieve file upload.
The advantage of using Flash is that you can solve browser compatibility issues. Before I wrote a quick copy feature is also used by Flash.
I've been using MVC for a long time, so let's take an example of MVC:
Uploadindex2.cshtml Code:
@{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <meta http-equiv="x-ua-compatible"Content="Ie=emulateie7"/> <title> uploads </title> <script src="~/swfupload/swfupload.js"Type="Text/javascript"></script> <script src="~/swfupload/handlers.js"Type="Text/javascript"></script> <script src="~/scripts/jquery-1.8.2.min.js"></script> <script type="Text/javascript">varswfu; Window.onload=function () {SWFU=Newswfupload ({//Backend SettingsUpload_url:"@Url. Action ("HandlerUpload2","Home")",//Upload Pathpost_params: {"Aspsessid":"< @Session .sessionid>" }, //File Upload SettingsFile_size_limit:"5 MB", File_Types:"*.jpg;*.gif", file_types_description:"JPG Images", File_upload_limit:0,//Zero means unlimited//Event Handler Settings-these functions as defined in Handlers.js//The handlers is not part of SWFUpload but is part of my website and control How//my website reacts to the SWFUpload events.Swfupload_preload_handler:preload, swfupload_load_failed_handler:loadfailed, File_queue_error_handler:filequeueerror, File_dialog_complete_handler:filedialogcomplete, Upload_progress_handler:uploadprogress, Upload_error_handler:uploaderror, Upload_su Ccess_handler:showdata, Upload_complete_handler:uploadcomplete,//Button SettingsButton_image_url:"/swfupload/images/xpbuttonnotext_160x22.png",//Set the button picture, note that if four consecutive sheetsBUTTON_PLACEHOLDER_ID:"Spanbuttonplaceholder",//set the button IDButton_width: the, Button_height: A, Button_text:'<span class= "button" > Please select upload picture <span class= "Buttonsmall" > (5 MB Max) </span></span>', Button_text_style:'. button {Font-family:helvetica, Arial, Sans-serif; font-size:14pt;}. buttonsmall {font-size:10pt;}', button_text_top_padding:1, button_text_left_padding:5, //Flash SettingsFlash_url:"/swfupload/swfupload.swf",//Relative to this fileFlash9_url:"/swfupload/swfupload_fp9.swf",//Relative to this filecustom_settings: {upload_target:"Divfileprogresscontainer" }, //Debug SettingsDebugfalse }); } //The method is executed after the upload is successful.function ShowData (file, serverdata) {$ ("#imgSrc"). attr ("src", Serverdata); } </script>"Form1"> <div id="content"> <div id="Swfu_container"style="margin:0px 10px;"> <div> <span id="Spanbuttonplaceholder"></span> <!--NOTE: This ID is consistent with the above--</div> "imgsrc"/><!---here to display uploaded images, this plugin used for asynchronous uploads--</div> </div> </form></body>View CodeBack-End Code:
PublicActionResult UploadIndex2 () {returnView (); } [HttpPost] PublicActionResult HandlerUpload2 () {HttpPostedFileBase file= request.files["Filedata"];//gets the file data. stringFileName = path.getfilename (file. FileName);//gets the file name. stringFileext = Path.getextension (fileName);//Get file Type stringFulldir =""; if(Fileext = =". jpg") { stringDIR ="/uploadimage/"+ DateTime.Now.Year +"-"+ DateTime.Now.Month +"-"+ DateTime.Now.Day +"/"; Directory.CreateDirectory (Path.getdirectoryname (Server.MapPath (dir)));//If there is no file directory, create.Fulldir = dir + OnLineBooks.App.Common.WebCommon.GetStreamMD5 (file. InputStream) + Fileext;//constructs a complete path, and takes the file stream the MD5 value as the file name, solves the file name duplicate question. File. SaveAs (Server.MapPath (Fulldir));//File SaveResponse.Write (Fulldir); } returnContent (Fulldir);//return picture Path}
View CodeSWFUpload file Download Link: Http://pan.baidu.com/s/1c2xIf5Y Password: Wphd
File upload-file asynchronous upload with SWF plugin