怎么样实现文件上传?高分求助!!!

star123qiu 2003-09-12 09:18:30
有一数据库wenjian.mdb,表中有三项filename、filetype和filevalue,分别用来存文件名、文件类型和文件内容。执行叶面有index.asp和savelogo.asp,分别用来选择文件和上传文件,选择文件的框名为file1.
我怎么样才能实现文件的上传,把文件存到数据库中?
大虾帮我。
...全文
43 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tonglu 2003-09-12
  • 打赏
  • 举报
回复
搜一下"化境无组件上传"一堆
zhangjun 2003-09-12
  • 打赏
  • 举报
回复
上传的文件最好不存到数据库中去,只保存路径,方法上面的说的很清楚了
alexbobof 2003-09-12
  • 打赏
  • 举报
回复
忘了说了,我qq:45280706
alexbobof 2003-09-12
  • 打赏
  • 举报
回复
这个论坛里无组件上传的帖子有很多,你可以找一下,要是没找到就加我qq,我给你传一份。
李睿_Lee 2003-09-12
  • 打赏
  • 举报
回复
去网上搜索一下无组件上传,到处都是.下载一个研究一下不就得了.
富察咪咪 2003-09-12
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/Read_Article.asp?Id=20378
coffee_cn 2003-09-12
  • 打赏
  • 举报
回复
sh.ce.net.cn/web8/tools/up.zip
asdmusic8 2003-09-12
  • 打赏
  • 举报
回复
using System;
using System.Web;
using System.Web.UI;


namespace CMyUpload
{
/// <summary>
/// MyUpload 的摘要说明。
/// </summary>
public class MyUpload
{
private System.Web.HttpPostedFile postedFile=null;
private string savePath="";
private string extension="";
private int fileLength=0;
public string uploadResult="";
//显示该组件使用的参数信息
public string Help
{
get
{
string helpstring;
helpstring="<font size=3>MyUpload myUpload=new MyUpload(); //构造函数";
helpstring+="myUpload.PostedFile=file1.PostedFile;//设置要上传的文件";
helpstring+="myUpload.SavePath=\"UpFile\\\";//设置要上传到服务器的路径,默认c:\\";
helpstring+="myUpload.FileLength=100; //设置上传文件的最大长度,单位k,默认1k";
helpstring+="myUpload.Extension=\"xls\";设置上传文件的扩展名,默认txt";
helpstring+="label1.Text=myUpload.Upload();//开始上传,并显示上传结果</font>";
helpstring+="<font size=3 color=red>Design By DgCoway 2003-9-9 All Right Reserved!</font>";
return helpstring;
}
}



public System.Web.HttpPostedFile PostedFile
{
get
{
return postedFile;
}
set
{
postedFile=value;
}
}



public string SavePath
{
get
{
if(savePath!="")
return savePath;
return "UpFile\\";
}
set
{
savePath=value;
}
}



public int FileLength
{
get
{
if(fileLength!=0) return fileLength;
return 1024;
}
set
{
fileLength=value*1024;
}
}



public string Extension
{
get
{
if(extension!="") return extension;
return "xls";
}
set
{
extension=value;
}
}



public string PathToName(string path)
{
int pos=path.LastIndexOf("\\");
return path.Substring(pos+1);
}


private string Get_date()
{
DateTime dt=DateTime.Now;
string day,month,minute,second,hour;
month=dt.ToString("MM");
day=dt.ToString("dd");
hour=dt.ToString("HH");
minute=dt.ToString("mm");
second=dt.ToString("ss");
string current_time=dt.Year.ToString()+month+day+hour+minute+second;
return current_time;
}

public bool Upload(Page par)
{
if(PostedFile!=null)
{
try
{
string fileName=PathToName(PostedFile.FileName);
if(!fileName.EndsWith(Extension))
{
uploadResult="你必须选择文件类型是 "+Extension+" 的文件!";
return false;
}
if(PostedFile.ContentLength>FileLength)
{
uploadResult= "文件太大!";
return false;
}
if(par!=null)
fileName=par.Request.UserHostAddress.ToString()+"_"+Get_date()+"_"+fileName;
else
fileName=Get_date()+"_"+fileName;

PostedFile.SaveAs(SavePath+fileName);

uploadResult= fileName;
return true;
}
catch(System.Exception exc)
{
uploadResult= exc.Message;
return false;
}
}else
{
uploadResult="请选择一个文件上传";
return false;
}
}
}
}

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧