Database: proimgs/abc1.jpg ||||
String [] ARRA = Dr ["picture"]. tostring (). Split ('|'); // retrieve the image
String strname = arr [0]. substring (8); "proimgs/" output from these eight characters:Abc1.jpg
String newname = strname. substring (0, strname. lastindexof ("."); output:ABC1
String pimg = ARRA [0]. substring (0, ARRA [0]. lastindexof (". ") +" p "+ ARRA [0]. substring (ARRA [0]. lastindexof (". "); output:Proimgs/ABC1P.jpg
When you use the fileupload control to obtain the file name, try to use the path. getfilename (uploadfile. postedfile. filename) method so that any browser can get the correct file name without containing the path.
String picture = ""; string strupath = server. mappath ("~ /Proimgs/"); If (this. fileupload1.filename. tostring ()! = "") {String strname1 = This. fileupload1.filename. tostring (); // name of the uploaded file
Int strsize1 = convert. toint32 (this. fileupload1.postedfile. contentlength. tostring (); // the size of the uploaded file string strtype1 = This. fileupload1.postedfile. contenttype. tostring (); // type of the uploaded file if (strtype1 = "image/pjpeg" | strtype1 = "image/BMP" | strtype1 = "image/GIF ") // determine whether the image type is {If (strsize1 <500000) {This. fileupload1.saveas (strupath + profname + strname1.substring (strname1.lastindexof (". "); // save the file to the server pp. im Gcopy (strupath, profname, strname1.substring (strname1.lastindexof (". "), 1); // watermark the image pp. imgsmoclass (strupath, profname, strname1.substring (strname1.lastindexof (". "); // category thumbnail pp. imgsmopro (strupath, profname, strname1.substring (strname1.lastindexof (". "), 1); // product thumbnail} else {response. write ("<JavaScript upload EAGE = 'javascript '> alert ('upload file is too large! '); History. go (-1); </SCRIPT> ") ;}} else {response. write ("<JavaScript upload EAGE = 'javascript '> alert ('upload file type is not an image! '); History. go (-1); </SCRIPT> ");} picture + =" proimgs/"+ profname +" 1 "+ strname1.substring (strname1.lastindexof (". ") +" | ";} else {picture + =" | ";} If (this. fileupload2.filename. tostring ()! = "") {String strname2 = This. fileupload2.filename. tostring (); // the uploaded file name int strsize2 = convert. toint32 (this. fileupload2.postedfile. contentlength. tostring (); // the size of the uploaded file string strtype2 = This. fileupload2.postedfile. contenttype. tostring (); // type of the uploaded file if (strtype2 = "image/pjpeg" | strtype2 = "image/BMP" | strtype2 = "image/GIF ") // determine whether the image type is {If (strsize2 <500000) {This. fileupload2.saveas (strupath + profn Ame + strname2.substring (strname2.lastindexof (". "); // save the file to the server pp. imgcopy (strupath, profname, strname2.substring (strname2.lastindexof (". "), 2); pp. imgsmopro (strupath, profname, strname2.substring (strname2.lastindexof (". "), 2); // thumbnail} else {response. write ("<JavaScript upload EAGE = 'javascript '> alert ('upload file is too large! '); History. go (-1); </SCRIPT> ") ;}} else {response. write ("<JavaScript upload EAGE = 'javascript '> alert ('upload file type is not an image! '); History. go (-1); </SCRIPT> ");} picture + =" proimgs/"+ profname +" 2 "+ strname2.substring (strname2.lastindexof (". ") +" | ";} else {picture + =" | ";}
// Add a watermark to the image, strpath: path; strname: file name; strtype file type; public static void imgcopy (string strpath, string strname, string strtype, int I) {try {// Add the image watermark string Path = strpath + strname + strtype; system. drawing. image image = system. drawing. image. fromfile (PATH); system. drawing. image copyimage = system. drawing. image. fromfile (system. web. httpcontext. current. server. mappath ("~ /Images/slogo.png "); // +"/slogo.png "); graphics G = graphics. fromimage (image); G. drawimage (copyimage, new rectangle (image. width-copyimage. width, image. height-copyimage. height, copyimage. width, copyimage. height), 0, 0, copyimage. width, copyimage. height, graphicsunit. pixel); G. dispose (); // Save the image after adding the watermark, delete the original image string newpath = strpath + strname + I + strtype; // + extension; // image. save (newpath); image. dispose (); // string strdelpath = strpath + strname; If (file. exists (PATH) // Delete the image {file. delete (PATH) ;}} catch (exception ex) {Throw new exception (ex. message );}}
// Thumbnail
Http://www.cnblogs.com/zengxiangzhan/archive/2009/09/17/1568535.html