foreground, the target of the form points to the IFRAME
<form action= "/emailhandler.ashx?action=upload" id= "Form1" Name= "Form1" enctype= "Multipart/form-data" method= " Post "target=" Hidden_frame "> <div class=" Up_file "id=" Up_file "> <input type=" file "class=" fl h_20 w_300 "id=" file "multiple=multiple name=" upload "onchange=" fileselected () "/> <input type=" Submit "value=" Upload "/> </div> <iframe name= ' hidden_frame ' id=" hidden_frame "style= ' Display:none ' > </iframe> <div id= "FileInfo" ></div> </form>
// Post-Upload callback method function Callback (msg) { document.getElementById ("file"). outerHTML = document.getElementById ("file"). outerhtml; $ (' #attr_url '). Val (msg); document.getElementById (' FileInfo '). InnerHTML + = "<p> upload success </p>" }
Background:
Case "Upload": #regionUploading files { stringPath =""; if(Context. Request.Files.Count >0) {httpfilecollection files= Context. Request.Files;//Accept File if(Files. Count >0) { foreach(stringIinchfiles) {Httppostedfile file=Files[i]; stringFileName = path.getfilename (file. FileName);//Get file name stringFileext = Path.getextension (fileName);//Get file Type if(! Directory.Exists (context. Server.MapPath ("/emailfiles/")) {directory.createdirectory (context. Server.MapPath ("/emailfiles/")); } stringDircstr ="/emailfiles/"+ Emp.uid +"/"; if(!directory.exists (context. Server.MapPath (DIRCSTR)) {Directory.createdire Ctory (Path.getdirectoryname) (context. Server.MapPath (DIRCSTR)); } stringName =dircstr+ datetime.now.year+"-"+datetime.now.month+"/"; if(!directory.exists (context. Server.MapPath (name))) {Directory.createdirecto Ry (Path.getdirectoryname) (context. Server.MapPath (name))); } stringFileloadname = name +datetime.now.day.tostring () +datetime.now.hour.tostring () +datetime.now.minute.tostring () + DateTime.Now.Second.ToString () +Fileext; File. SaveAs (context. Server.MapPath (Fileloadname)); Path+ = Fileloadname +','; }} Path= path. TrimEnd (','); Context. Response.Write ("<script>parent.callback ('"+ Path +"') </script>");//Call the foreground callback method} Break; } #endregion
Uploading using Input=file