无为清净楼资源网 Design By www.qnjia.com
数据库:保存图片的数据格式 图象二进制数据储存字段
前台:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadWork.aspx.cs" Inherits="meishuguan.UploadWork" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
height: 25px;
}
</style>
</head>
<body>
<script type="text/javascript">
function checkData() {
var fileName = document.getElementById("UploadImage").value;
alert(fileName);
//var fileName = document.getElementsByName("UploadImage").value;
if (fileName == "")
return;
var exName = fileName.substr(fileName.lastIndexOf(".") + 1).toUpperCase();
//alert(exName)
if (exName == "JPG" || exName == "BMP" || exName == "GIF") {
var imgpath = fileName.src;
alert(imgpath);
document.getElementById("PreviewImage").src = imgpath;
document.write(fileName);
}
else {
alert("请选择正确的图片文件")
document.getElementById("PreviewImage").value = ""
}
}
</script>
<form method="post" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="MessageLabel" runat="server"></asp:Label>
</td>
<td class="style2">
&nbsp;
</td>
</tr>
<tr>
<td class="style2">
<input id="UploadImage" name = "UploadImage" type="file" runat="server" onchange="checkdata()" />
</td>
<td class="style2">
&nbsp;
<img id="PreviewImage" alt="" src="/UploadFiles/2021-04-02/"></tr>
<tr>
<td>
<asp:Button ID="UploadButton" runat="server" Text="确定" OnClick="UploadButton_Click" />
</td>
<td>
&nbsp;
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

后台:
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;
namespace meishuguan
{
public partial class UploadWork : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void UploadButton_Click(object sender, EventArgs e)
{
HttpPostedFile UpFile = UploadImage.PostedFile;
int ImageLength = UpFile.ContentLength;
if (ImageLength == 0)
{
MessageLabel.Text = "请选择要上传的图片";
return;
}
if (ImageLength > Int32.Parse(Application["MaxImageLength"].ToString()))
{
MessageLabel.Text = "图片大小不能大于2M";
return;
}
Stream ImageStream = UpFile.InputStream;
Byte[] ImageByte = new Byte[ImageLength];
ImageStream.Read(ImageByte, 0, ImageLength);
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
string sqlstring = "insert into [Work](MID,image,length) values(@MID,@image,@length)";
SqlCommand command = new SqlCommand(sqlstring, connection);
command.Parameters.Add("@MID", System.Data.SqlDbType.Int).Value = Session["MID"].ToString();
command.Parameters.Add("@image", System.Data.SqlDbType.Image, ImageLength).Value = ImageByte;
command.Parameters.Add("@length", System.Data.SqlDbType.Int).Value = ImageLength;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
MessageLabel.Text = "图片上传成功";
}
}
}
标签:
上传图片,数据库

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。