作者:wyhw 時(shí)間: 2003-10-01 文檔類型:轉(zhuǎn)載 來自:藍(lán)色理想
代碼拷貝框<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 (姓名,班級(jí),介紹,屬性) 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='/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)提交了留言,請(qǐng)等待服務(wù)器應(yīng)答!"); return(false); } requestsubmitted=true; return (true); } //--> </SCRIPT> <Html> <Body BgColor=White> <H3 align="center">請(qǐng)正確填寫下面各項(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="請(qǐng)輸入圖片說明"> </asp:RequiredFieldValidator><br> <Asp:button id="Upload" OnClick="UploadFile" Text="上傳圖片" runat="server"/> </form> </Body> </Html> [Ctrl+A 全部選擇 然后拷貝]
出處:藍(lán)色理想 責(zé)任編輯:藍(lán)色
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
藍(lán)色理想版權(quán)申明:除部分特別聲明不要轉(zhuǎn)載,或者授權(quán)我站獨(dú)家播發(fā)的文章外,大家可以自由轉(zhuǎn)載我站點(diǎn)的原創(chuàng)文章,但原作者和來自我站的鏈接必須保留(非我站原創(chuàng)的,按照原來自一節(jié),自行鏈接)。文章版權(quán)歸我站和作者共有。
轉(zhuǎn)載要求:轉(zhuǎn)載之圖片、文件,鏈接請(qǐng)不要盜鏈到本站,且不準(zhǔn)打上各自站點(diǎn)的水印,亦不能抹去我站點(diǎn)水印。
特別注意:本站所提供的攝影照片,插畫,設(shè)計(jì)作品,如需使用,請(qǐng)與原作者聯(lián)系,版權(quán)歸原作者所有,文章若有侵犯作者版權(quán),請(qǐng)與我們聯(lián)系,我們將立即刪除修改。