Description (2017-10-8-23:03:43):
1. Behind the content are some assorted, bits and pieces, before all directly skipped, but in fact, it is very important, this time to re-learn to be serious and really knocked over.
2. Tomorrow at noon 9th to return to Beijing, tonight with the introduction of the sister chatted for one hours, hey!
3. Add a watermark to the picture!
Index.html
1<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">2"http://www.w3.org/1999/xhtml">34<title></title>56<body>7<form action="index.ashx"Method="Post"Enctype="Multipart/form-data">8<input type="file"Name="file"/>9<input type="text"Name="txt"/>Ten<input type="Submit"Value="Upload"/> One</form> A</body> -Index.ashx
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.IO;6 7 namespace_02_ image Upload8 {9 /// <summary>Ten ///Summary description of index One /// </summary> A Public classIndex:ihttphandler - { - the Public voidProcessRequest (HttpContext context) - { -Context. Response.ContentType ="text/html"; - //receiving file Data +Httppostedfile file = context. request.files["file"]; - if(File = =NULL) + { AContext. Response.Write ("No pictures uploaded! "); at } - Else - { - - //string fileName = Path.getfilename (file. FileName); - //Plus globally unique identification to prevent picture duplication inGuid g =Guid.NewGuid (); - stringFileName =Guid.NewGuid (). ToString (); to //Get extension + stringFileext =path.getextension (file. FileName); - //relative Path the stringFilePath ="image/"+ DateTime.Now.Year +"/"+ DateTime.Now.Month +"/"+ DateTime.Now.Day +"/"; * //Absolute Path $ //Create a folder, named after month and dayPanax Notoginseng stringFilerealpath = context. Request.mappath ("image/") + DateTime.Now.Year +"/"+ DateTime.Now.Month +"/"+ DateTime.Now.Day +"/"; - directory.createdirectory (filePath); the //determine file types to prevent uploading viruses + if(Fileext = =". jpg") A { theFile. SaveAs (Filerealpath + fileName +fileext); + //The picture path of this place needs to be relative path, otherwise it will not show -Context. Response.Write (""+ FilePath + fileName + fileext +"'/></body>"); $ } $ - } - } the - Public BOOLisreusableWuyi { the Get - { Wu return false; - } About } $ } -}
Asp. NET study notes (4)--Upload images