通过ASP把文件传到指定的文件夹photo中,不需要传到数据库中,请给出代码,以及说明,特别是传到哪个

通过ASP把文件传到指定的文件夹photo中,不需要传到数据库中,请给出代码,以及说明,特别是传到哪个文件夹中,文件夹的名字出现在代码的哪个地方

第1个回答  2010-09-20
这是组件上传的,SA FileUp上传组件。不知道是不是你想要的。

uppath="../../phohot/" '你指定的photo文件夹

set fso=CreateObject("scripting.filesystemobject")
folderpath = server.mappath(uppath)

If Not fso.FolderExists(folderpath) Then'判定文件夹是否存在,不存在则生成一个
fso.CreateFolder(folderpath)
End If

formPath=uppath & "/"

’开始上传
For Each strFormElement In oFileUp.Form
If IsObject(oFileUp.Form(strFormElement)) Then '如果是文件
If Not oFileUp.Form(strFormElement).IsEmpty Then '--文件不为空
flagOK=1

'--不是文件或文件大于限制,设置错误信息
If oFileUp.Form(strFormElement).TotalBytes=0 Then
flagOK=0
ElseIf oFileUp.Form(strFormElement).TotalBytes>1024*1024 Then
flagOK=0
errMsg=errMsg+"文件:"&oFileUp.Form(strFormElement).UserFileName&" 文件大于1M,请压缩后重新上传"
Else
strShortFileName = mid(oFileUp.Form(strFormElement).UserFileName,InStrRev(oFileUp.Form(strFormElement).UserFileName, "\")+1) '取得文件名
strExtension = Mid(strShortFileName, InStrRev(strShortFileName, ".")) '取得扩展名

Select Case LCase(strExtension) Case ".XLS",".DOC",".PPT",".xls",".doc",".ppt",".gul",".GUL",".jpg",".jpeg",".JPG",".JPEG",".XLSX",".DOCX",".PPTX",".xlsx",".docx",".pptx",".PDF",".pdf"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
errMsg=errMsg+"<B>错误:</B> 扩展名为 <I>"&strExtension&" </I> 的文件不能被上传。"
End Select
End If 'end if 文件大小判断

If flagOK=1 Then '如果文件通过检查,保存文件
filename=year(now())&month(now())&day(now())&hour(now())&minute(now())&second(now())&strShortFileName
oFileUp.Form(strFormElement).SaveInVirtual formPath&filename
response.write "上传成功!"
End If

Else
errMsg=errMsg+strFormElement & "请选择要上传的文件!"
End If '--end if 对象为空
End If '--end if 是否是文件
Next
Set oFileUp = Nothing '删除此对象

'=====如果有错,输出错误信息=====
if errMsg<>"" then
response.write errMsg
response.write "<INPUT type='button' onClick='history.go(-1)' value='返回' class='myInput'>"
end if

希望能帮到你本回答被网友采纳
第2个回答  2010-09-21
前台
<body>
<form id="form1" runat="server">
<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

</form>
</body>
后台传到web目录的photo文件夹中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.IO;

public partial class test : System.Web.UI.Page
{
public static string str = "123";
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
Fileupload1.SaveAs(Server.MapPath("~/photo") +"\\"+ Fileupload1.FileName);
}
catch(Exception ex)
{

}
}
}本回答被提问者采纳