本文介绍了下列代码在技术上是否正确适用于“图片上传"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System.Drawing;
using System.Web.UI.WebControls;


if (ImageUploader.HasFile)
            {
                string imagePath = ConfigurationManager.AppSettings["PhotoGalleryImage"].ToString();

                System.Drawing.Image img = System.Drawing.Image.FromStream(ImageUploader.PostedFile.InputStream);
                string imageName = ImageUploader.FileName;

                Array arrayImage = imageName.Split('.');
                imageName = System.DateTime.Now.Ticks.ToString() + "." + arrayImage.GetValue(1).ToString();
                string a = imageName;
                Array extension = a.Split('.');


                if (Convert.ToString(extension.GetValue(1)) == "jpg" || Convert.ToString(extension.GetValue(1)) == "gif" || Convert.ToString(extension.GetValue(1)) == "BMP" || Convert.ToString(extension.GetValue(1)) == "bmp" || Convert.ToString(extension.GetValue(1)) == "GIF" || Convert.ToString(extension.GetValue(1)) == "JPG" || Convert.ToString(extension.GetValue(1)).ToUpper() == "PNG")
                {
                    int variableHGeight = (img.Height / img.Width) * 345;
                    ImageUploader.PostedFile.SaveAs(Server.MapPath(imagePath) + imageName);
                   


                    System.Drawing.Image PostedImg = System.Drawing.Image.FromStream(ImageUploader.PostedFile.InputStream);

}
}

推荐答案


这篇关于下列代码在技术上是否正确适用于“图片上传"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 10:31