把下面的代码保存为Upload.aspx即可运行(事先在同目录下建立一个Upload文件夹保存上传的文件,再建立一个数据库、表Upload,字段ID:自动编号,FilePath:文本型):
<%@Import Namespace =Namespace="System.Data"%>
<%'@Import Namespace="System.Data.OleDb"%> <!--Access数据库用这个-->
<%@Import Namespace =Namespace="System.Data.SqlClient"%> <!--SQL Server数据库用这个-->
<script language="VB" runat="server">
Sub UploadFile()Sub UploadFile(sender As Object, e As EventArgs)
Dim FileExt
FileExt = LCase(Right(Trim(FileUp.Value),3))
If FileExt = "gif" Or FileExt = "jpg" Or FileExt = "bmp" Or FileExt = "png" Or FileExt = "tif" Or LCase(Right(Trim(FileUp.Value),4)) = "jpeg" Then
If FileUp.PostedFile.ContentLength = 0 Then
FileInfo.Visible = False
Exit Sub
Else
FileInfo.Visible = True