国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net上傳圖片并同時(shí)生成縮略圖

2024-07-10 12:57:33
字體:
供稿:網(wǎng)友


<script language="vb" runat="server">
sub uploadfile(sender as object, e as eventargs)

if fileup.postedfile.contentlength = 0 then
fileinfo.visible = false
exit sub
else
fileinfo.visible = true
fdisplay1.visible = true
end if

fsize.text ="上傳文件大小"+ cstr(fileup.postedfile.contentlength/1024)+"kb"
fname.text = "已上傳文件名:"+fileup.postedfile.filename+"<br>"+fname.text

'寫入數(shù)據(jù)庫
on error resume next
dim myconn as sqlconnection
dim mycomm as sqlcommand
dim sql as string
dim id as integer
dim image,anewimage as system.drawing.image
dim width,height,newwidth,newheight as integer
dim callb as system.drawing.image.getthumbnailimageabort
myconn=new sqlconnection(configurationsettings.appsettings("數(shù)據(jù)庫"))
myconn.open()
sql="insert into picture (姓名,班級,介紹,屬性) values ('"&request.cookies("dgxyl").values("dgxylname")&"','"&request.cookies("dgxyl").values("dgxylbj")&"','"&trim(request("textbox1"))&"','"&request("r1")&"')"
mycomm=new sqlcommand(sql,myconn)
mycomm.executenonquery()
myconn.close()

dim mycommand as new sqlcommand("select top 1 id from picture order by id desc", myconn)
mycommand.connection.open()
dim myreader as sqldatareader=mycommand.executereader()
if myreader.read() then
id=myreader("id")
end if
myconn.close()
'保存圖片
fileup.postedfile.saveas( server.mappath("/classpic/")&cstr(id)&".jpg" )
'生成縮略圖
image=system.drawing.image.fromfile(server.mappath("/classpic/"+cstr(id)+".jpg"))
width=image.width
height=image.height
if width>height then
newwidth=250
newheight=image.height/image.width*newwidth
else
newheight=250
newwidth=image.width/image.height*newheight
end if
response.write("id="+cstr(id)+"width="+cstr(width)+";height="+cstr(height)+" ")
response.write("newwidth="+cstr(newwidth)+";newheight="+cstr(newheight)+"<br>")

anewimage=image.getthumbnailimage(newwidth,newheight,callb,new system.intptr())
anewimage.save(server.mappath("/smallpic/"+cstr(id)+".jpg"))
image.dispose()


dim filesplit() as string = split( fileup.postedfile.filename, "/" )
dim filename as string = filesplit(filesplit.length-1)
dim exts() as string = split( filename, "." )
dim ext as string = lcase(exts(exts.length-1))

fdisplay.text = "<a target='_blank' href='http://www.163design.net/classpic/"&cstr(id)&".jpg"& "'>查看上傳文件</a>"
fdisplay1.text="<a href='/picture/default.asp?bj="&cstr(request.cookies("dgxyl").values("dgxylbj"))&"'>返回</a>"
end sub
</script>
<script language=javascript>
<!--
var requestsubmitted=false;
function guestbook_validator(theform)
{
//檢查是否從新提交
if (requestsubmitted==true){
alert("你已經(jīng)提交了留言,請等待服務(wù)器應(yīng)答!");
return(false);
}
requestsubmitted=true;

return (true);
}
//-->
</script>
<html>
<body bgcolor=white>
<h3 align="center">請正確填寫下面各項(xiàng)</h3>
<hr></h3>
<div id="fileinfo" visible="false" runat="server">
<asp:label id="fsize" runat="server"/><br>
<asp:label id="fname" runat="server"/><br>
<asp:label id="fdisplay" runat="server"/>
<asp:label id="fdisplay1" runat="server"/>
</div>
<form enctype="multipart/form-data" onsubmit="return guestbook_validator(this)" runat="server">
上傳文件
<input type="file" id="fileup" runat="server" size="20"><br>
圖片屬性:<input type="radio" value="<%=request.cookies("dgxyl").values("dgxylbj")%>" name="r1" checked>本班<input type="radio" value="全校" name="r1">全校(本班則只在本班顯示,全校則在全校顯示)<p>
圖片說明:<br>
<asp:textbox id="textbox1" runat="server" width="233px" height="141px">
</asp:textbox>
<asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server" controltovalidate="textbox1" errormessage="請輸入圖片說明">
</asp:requiredfieldvalidator><br>
<asp:button id="upload" onclick="uploadfile" text="上傳圖片" runat="server"/>
</form>
<hr>
<p>注意:</p>
<ol>
<li><b>嚴(yán)禁上傳污染環(huán)境的照片,否則賬號(hào)將被刪除!</b></li>
<li><font color="#808000"><b>請?jiān)敿?xì)填寫照片說明,圖片說明不詳細(xì)將會(huì)被視為亂傳圖片,將會(huì)被刪除!</b></font></li>
</ol>
<p> </p>

</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 烟台市| 西乌珠穆沁旗| 墨江| 东山县| 油尖旺区| 石泉县| 巴彦淖尔市| 永泰县| 马关县| 宁城县| 广汉市| 合水县| 苏尼特左旗| 二手房| 石河子市| 五家渠市| 平塘县| 汝阳县| 灌阳县| 郧西县| 宁城县| 河池市| 石楼县| 桂阳县| 冀州市| 岑巩县| 灵石县| 平罗县| 福安市| 祁东县| 桐梓县| 汉中市| 张北县| 凭祥市| 南通市| 塘沽区| 龙胜| 长泰县| 夏邑县| 祥云县| 西充县|