如何在服务器上传图像 [英] How to upload image in server

查看:78
本文介绍了如何在服务器上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在具有特定大小的服务器上上传图像并在数据库中保存路径

解决方案

您无法控制用户发送给您的图像的大小:全部您可以做的是接收上传文件,将其加载到图像中并检查尺寸。如有必要,您可以重新缩放它(Google会帮助您),或拒绝它,以便用户上传另一个。



上传很简单:http://code.msdn.microsoft.com/Uploadedit-image-in-ASPNET-b96367a9/view /讨论 [ ^ ]


嗨...

查看此链接。

从sql数据库保存本地文件夹中的图像 [ ^ ]

谢谢。


  protected   void  Page_Load( object  sender,EventArgs e)
{

}
protected void Button2_Click( object sender,EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = Server.HtmlEncode(FileUpload1。文件名);
string extension = System.IO.Path.GetExtension(fileName);
System.Drawing.Image image_file = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
int image_height = image_file.Height;
int image_width = image_file.Width;
int max_height = 150 ;
int max_width = 150 ;

image_height =(image_height * max_width)/ image_width;
image_width = max_width;

if (image_height > max_height)
{
image_width =(image_width * max_height)/ image_height;
image_height = max_height;
}

位图bitmap_file = new 位图(image_file,image_width,image_height);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
bitmap_file.Save(Server.MapPath( 〜/ uploadimage / + filename)) ;



SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ dbconnection]。ToString());
con.Open();
string query = INSERT INTO cpu(图片)VALUES文件名;
SqlCommand cmd = new SqlCommand(query,con);
cmd.ExecuteNonQuery();
con.Close();


How to upload image in server with specific size and save path in database

解决方案

You can't control the size of the image the user sends you: all you can do is receive the upload file, load it into an Image and check the dimensions. If necessary, you can then rescale it (Google will help you there), or reject it so the user uploads another.

Upload is easy: http://code.msdn.microsoft.com/Uploadedit-image-in-ASPNET-b96367a9/view/Discussions[^]


Hi...
See this link.
Save image in local Folder from sql database[^]
thank u.


protected void Page_Load(object sender, EventArgs e)
   {

   }
   protected void Button2_Click(object sender, EventArgs e)
   {
       if (FileUpload1.HasFile)
       {
           string fileName = Server.HtmlEncode(FileUpload1.FileName);
           string extension = System.IO.Path.GetExtension(fileName);
           System.Drawing.Image image_file = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
           int image_height = image_file.Height;
           int image_width = image_file.Width;
           int max_height = 150;
           int max_width = 150;

           image_height = (image_height * max_width) / image_width;
           image_width = max_width;

           if (image_height > max_height)
           {
               image_width = (image_width * max_height) / image_height;
               image_height = max_height;
           }

           Bitmap bitmap_file = new Bitmap(image_file, image_width, image_height);
           System.IO.MemoryStream stream = new System.IO.MemoryStream();
           string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
           bitmap_file.Save(Server.MapPath("~/uploadimage/" + filename));



           SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
           con.Open();
           string query = "INSERT INTO cpu (image) VALUES filename;
           SqlCommand cmd = new SqlCommand(query, con);
           cmd.ExecuteNonQuery();
           con.Close();


这篇关于如何在服务器上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆