asp文件上传,路径传入数据库,图片保存在文件夹
百度了几天,试了N多次,要不是有些没给出数据库具体结构,要么就是数据库字段给详细写出了,代码有误!问题很简单----建立一个文件域,插入有个名教上传的按扭,点击上传,图片...
百度了几天,试了N多次,要不是有些没给出数据库具体结构,要么就是数据库字段给详细写出了,代码有误!
问题很简单----建立一个文件域,插入有个名教上传的按扭,点击上传,图片传到某个文件夹,数据库可以查看到该图片的路径。
最好是1.可以限制文件的类型,
2.可以限制文件的大小。
ok没了 展开
问题很简单----建立一个文件域,插入有个名教上传的按扭,点击上传,图片传到某个文件夹,数据库可以查看到该图片的路径。
最好是1.可以限制文件的类型,
2.可以限制文件的大小。
ok没了 展开
5个回答
2013-09-12
展开全部
给你段代码,两个文件,你上面的要求都能达到:
《upload_file.asp》此页面作为弹出窗口,代码如下:
<!--#include file="UploadClass.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上传</title>
<link href="images/css.css" rel="stylesheet" type="text/css">
<body bgcolor="#FFFFFF" leftmargin="5" topmargin="20">
<%
Dim Admin_Flag,action
Dim File_ext,UploadSize,Uploadpath
Dim Filepath,Filename,Randnum
Dim Fileext_a,Fileext,UpMode
formname=Request.QueryString("formname")'父页面form表单名字
textname=Request.QueryString("textname")'父页面form内存放图片上传后路径的文本框名字
if textname="AdsFilePath" then '根据文本框名字确定文件保存的路径
UploadPath="adpic/"
elseif textname="WebLogo" then
UploadPath="WebLogoFile/"
elseif textname="ShopPic" then
UploadPath="Shop_Pic/"
elseif textname="Smaillpic" then
UploadPath="Smaill_pic/"
elseif textname="Bannapic" then
UploadPath="Banna_pic/"
end if
UploadSize=1000
File_ext="jpg,gif,swf"
Select Case Request.QueryString("action")
Case "upload"
Call Main()
Call UpLoad()
Case Else
Call Main()
End Select
Sub Main()
%>
<Form name="myform" method="post" action="?action=upload&formname=<%=formname%>&textname=<%=textname%>" enctype="multipart/Form-data" >
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="table">
<tr>
<th align="center" class="table_titl">文件上传</th>
</tr>
<tr>
<td height="30" align="center" class="wz" ID="strMsg">允许上传的文件类型:<%=file_ext%> </td>
</tr>
<tr>
<td height="30" align="center" class="wz">文件上传大小限制:<%=UploadSize%>K </td>
</tr>
<tr>
<td height="30" align="center" class="wz"> 请选择上传文件:
<input type="file" name="file1" size=20 class=text>
<input type="hidden" name="filename">
</td>
</tr>
<tr>
<td height="30" align="center" class="wz">
<input type="submit" name="Submit" value="上传" onClick="filename.value=file1.value;" class=button>
</td>
</tr>
</table>
</Form>
</body>
</html>
<%
End Sub
Sub UpLoad()
soft_upload()
End Sub
Sub Soft_Upload()
Dim upload,file,uploadsuc,splitFile
Dim upName
set upload=new upfile_class
upload.GetData (-1)
filePath=UploadPath
If right(filePath,1)<>"/" Then filePath=filePath&"/"
For Each upName In upload.file
Set file=upload.file(upName)
If file.filesize<1 Then
Response.Write "<script language=javascript>strMsg.innerHTML='请先选择你要上传的文件'</script>"
Response.end
End If
fileExt=LCase(file.FileExt)
uploadsuc=False
splitFile=Split(File_ext,",")
For i=0 to UBound(splitFile)
If fileEXT=Trim(LCase(splitFile(i))) Then
uploadsuc=True
Exit For
Else
uploadsuc=False
End If
Next
If uploadsuc=False Then
Response.Write "<script language=javascript>strMsg.innerHTML='文件格式不正确'</script>"
Response.end
End If
If file.FileSize>UploadSize*1024 Then
Response.Write "<script language=javascript>strMsg.innerHTML='文件大小超过了限制'</script>"
Response.end
End If
Randomize
filename=filePath&"Love_"&Year(Now)&Month(Now)&Day(Now)&hour(Now)&minute(Now)&second(Now)&randNum&"."&fileExt
file.SaveToFile Server.mappath("../"&FileName) ''保存文件
Check_picwords("../"&FileName) '检查上传文件是否存在违法代码
Response.Write "<script>"
Response.Write "opener."&formname&"."&textname&".value='"&filename&"';"
Response.Write "window.close();"
Response.Write "</script>"
Next
Set file=Nothing
Set upload=Nothing
End Sub
%>
等下补充
《upload_file.asp》此页面作为弹出窗口,代码如下:
<!--#include file="UploadClass.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件上传</title>
<link href="images/css.css" rel="stylesheet" type="text/css">
<body bgcolor="#FFFFFF" leftmargin="5" topmargin="20">
<%
Dim Admin_Flag,action
Dim File_ext,UploadSize,Uploadpath
Dim Filepath,Filename,Randnum
Dim Fileext_a,Fileext,UpMode
formname=Request.QueryString("formname")'父页面form表单名字
textname=Request.QueryString("textname")'父页面form内存放图片上传后路径的文本框名字
if textname="AdsFilePath" then '根据文本框名字确定文件保存的路径
UploadPath="adpic/"
elseif textname="WebLogo" then
UploadPath="WebLogoFile/"
elseif textname="ShopPic" then
UploadPath="Shop_Pic/"
elseif textname="Smaillpic" then
UploadPath="Smaill_pic/"
elseif textname="Bannapic" then
UploadPath="Banna_pic/"
end if
UploadSize=1000
File_ext="jpg,gif,swf"
Select Case Request.QueryString("action")
Case "upload"
Call Main()
Call UpLoad()
Case Else
Call Main()
End Select
Sub Main()
%>
<Form name="myform" method="post" action="?action=upload&formname=<%=formname%>&textname=<%=textname%>" enctype="multipart/Form-data" >
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="table">
<tr>
<th align="center" class="table_titl">文件上传</th>
</tr>
<tr>
<td height="30" align="center" class="wz" ID="strMsg">允许上传的文件类型:<%=file_ext%> </td>
</tr>
<tr>
<td height="30" align="center" class="wz">文件上传大小限制:<%=UploadSize%>K </td>
</tr>
<tr>
<td height="30" align="center" class="wz"> 请选择上传文件:
<input type="file" name="file1" size=20 class=text>
<input type="hidden" name="filename">
</td>
</tr>
<tr>
<td height="30" align="center" class="wz">
<input type="submit" name="Submit" value="上传" onClick="filename.value=file1.value;" class=button>
</td>
</tr>
</table>
</Form>
</body>
</html>
<%
End Sub
Sub UpLoad()
soft_upload()
End Sub
Sub Soft_Upload()
Dim upload,file,uploadsuc,splitFile
Dim upName
set upload=new upfile_class
upload.GetData (-1)
filePath=UploadPath
If right(filePath,1)<>"/" Then filePath=filePath&"/"
For Each upName In upload.file
Set file=upload.file(upName)
If file.filesize<1 Then
Response.Write "<script language=javascript>strMsg.innerHTML='请先选择你要上传的文件'</script>"
Response.end
End If
fileExt=LCase(file.FileExt)
uploadsuc=False
splitFile=Split(File_ext,",")
For i=0 to UBound(splitFile)
If fileEXT=Trim(LCase(splitFile(i))) Then
uploadsuc=True
Exit For
Else
uploadsuc=False
End If
Next
If uploadsuc=False Then
Response.Write "<script language=javascript>strMsg.innerHTML='文件格式不正确'</script>"
Response.end
End If
If file.FileSize>UploadSize*1024 Then
Response.Write "<script language=javascript>strMsg.innerHTML='文件大小超过了限制'</script>"
Response.end
End If
Randomize
filename=filePath&"Love_"&Year(Now)&Month(Now)&Day(Now)&hour(Now)&minute(Now)&second(Now)&randNum&"."&fileExt
file.SaveToFile Server.mappath("../"&FileName) ''保存文件
Check_picwords("../"&FileName) '检查上传文件是否存在违法代码
Response.Write "<script>"
Response.Write "opener."&formname&"."&textname&".value='"&filename&"';"
Response.Write "window.close();"
Response.Write "</script>"
Next
Set file=Nothing
Set upload=Nothing
End Sub
%>
等下补充
2013-09-12
展开全部
这个问题很简单吧?随便在网上下载一个bbs或者销售网的源码就好了啊。
bbs的头像上传页面和销售网的商品图片上传模块都是有这些功能的,参考一下就好了。
bbs的头像上传页面和销售网的商品图片上传模块都是有这些功能的,参考一下就好了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-12
展开全部
用FileUpload控件
按钮下代码
string FileName;
FileName = this.FileUpload1.PostedFile.FileName;
if ("" != FileName)
{
//上传图片
FileInfo file = new FileInfo(FileName);
string Name = file.Name;
string type = file.Extension;
if (".jpg" != type.ToLower() && ".gif" != type.ToLower() && ".bmp" != type.ToLower())
{
Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("PCimage") + "\\" + Name);//保存到PCImage文件夹下
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("insert into 表 values(@路径)",database.GetOpen());
cmd.Parameters.Add("@路径", SqlDbType.VarChar, 50).Value = FileName.Text;
cmd.ExecuteNonQuery();
}
按钮下代码
string FileName;
FileName = this.FileUpload1.PostedFile.FileName;
if ("" != FileName)
{
//上传图片
FileInfo file = new FileInfo(FileName);
string Name = file.Name;
string type = file.Extension;
if (".jpg" != type.ToLower() && ".gif" != type.ToLower() && ".bmp" != type.ToLower())
{
Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("PCimage") + "\\" + Name);//保存到PCImage文件夹下
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("insert into 表 values(@路径)",database.GetOpen());
cmd.Parameters.Add("@路径", SqlDbType.VarChar, 50).Value = FileName.Text;
cmd.ExecuteNonQuery();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-12
展开全部
你直接图片存数据库不就没那么麻烦了啊!?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询