How to upload pictures.

xiaoxiao2021-04-03  220

This is what I have encountered at work. You can save the picture to the specified folder and save the URL to the database. And the file name of the picture is randomly generated. This will not have a picture coverage. The probably code is as follows. Only refer to.

IF (file_pic.postedfile.filename! = "" && file_pic.postedfile! = null) {string [] aa = {"jpg", "gif", "bmp"}; string filename = system.io.path.getFileName FILE_PIC.POSTEDFILE.FILENAME); String [] Pictype = filename.split ('.'); String filetype = Pictype [Pictype.Length - 1]; if (Array.indexof (AA, FILETYPE.TOLOWER ())> = 0 ) // Determine if the file type is .jpg and .gif {if (! System.io.Directory.exists (server.mappath ("))) {system.io.directory.createdirectory (Server.mAppath ("../ images / hb_picture /")));} // Save the URL of the picture to the database in the database in the form of the random number and time. "Int RD = R. Next (1000); string strpic1 = system.datetime.now.tostring ("YYYYMMDDHHMMSS") rd.tostring () "." Filetype;

String path = server.mappath ("../ images / hb_picture /"); // relative path PATH = StrPic1; // Save the picture to the specified folder StrURL = "/ images / hb_picture /" strPic1; // put the picture address in the database file_pic.postedfile.saveas (path); string str1 = "Insert Into HB_PIC (FID, FTYPE, TITLE, PICURL) VALUES ('" txtid.text ",'" ftype " ',' " Title ", '" Strull ") "; kubao.commonprj.dba.sql.Exesqlcommand (kubao.cls_classlib.conn_mov, str1); label1.text =" Submit success! ";} else { Label1.text = "The uploaded picture format is incorrect!";}} Else {label1.text = "No upper transmission!";

转载请注明原文地址:https://www.9cbs.com/read-131663.html

New Post(0)