当前位置:首页 » 文件管理 » 大文件上传源码

大文件上传源码

发布时间: 2023-06-28 10:25:52

① 我需要使用winform实现大文件(大概20M左右)上传到iis7部署的一个站点,如何实现希望有源码

完全不需要使用winform来实现这个功能,因为用户还需要单独下载这个应用程序。比较麻烦。

用户体验非常好的大文件上传控件,北京新颖网络做的不错,楼主可以试试北京新颖网络FTP或者HTTP文件上传控件。北京新颖网络的FTP上传控件还支持断点续传,这个功能非常不错。也比较稳定。

② 急求ASP源码:上传文件大小限定,图片尺寸自动调整

三个页:选择页,上传页sub.asp,调用的代码页upload.inc,

我自己就在用这个,LZ给分吧

1浏览上传:
<form action="sub.asp"迅扰雹 method="post" enctype="multipart/form-data" target="_self">
<input type="亩帆file" name="src" size="20" value="浏览">
<input type="submit" value="上传" name="B1" IsShowProcessBar="True">
</form>

sub.asp 执行上传并返回地址,同时保存文件名在session(ccc)中

<!--#include FILE="upload.inc"-->
<%
dim upload,file,formName,formPath,iCount,fileformat
set upload=new upload_F
function MakedownName()
dim fname
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
fname = int(fname) + int((10-1+1)*Rnd + 1)
MakedownName=fname
end function
formPath="upload/"
iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象

fileformat=lcase(right(file.filename,4))

if fileformat=".asp" or fileformat=".htm" then
response.write"<script>alert('文件格式不对,请重新上传!');location='"&request.ServerVariables("HTTP_REFERER")&"'</script>"
response.end
end if

if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
newname=MakedownName()&"."&mid(file.FileName,InStrRev(file.FileName, ".")+1)

session("ccc")=newname
file.SaveAs Server.mappath(formPath&newname) ''保存李昌文件
iCount=iCount+1
else
response.write "<font style=FONT-SIZE:9pt>未找到文件 <A HREF=javascript:history.back(1)>重新上传</A><font style=FONT-SIZE:9pt>"
response.end
end if
next
%>

<%
response.write "<a href='upload/"&newname&"' target=_blank>upload/"&newname&" </a>("&cint(file.FileSize/1024)&"K) 上传成功!"
%>

<%
set file=nothing
set upload=nothing ''删除此对象
%>

upload.inc 页的代码如下:

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_Stream

Class upload_F

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="upload Version 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_Stream=CreateObject("Adodb.Stream")
upfile_Stream.mode=3
upfile_Stream.type=1
upfile_Stream.open
upfile_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_Stream.EOS then Exit for
c=ascB(upfile_Stream.Read(1))
If c > 127 Then
if upfile_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_Stream.Size-theLen
if i>upfile_Stream.size then exit Function
upfile_Stream.Position=i-1
if AscB(upfile_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_Stream.close
set upfile_Stream=nothing
End Sub

Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_Stream.position=FileStart-1
upfile_Stream.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>

③ c# .net文件上传文件的源代码

string path = Server.MapPath("/");
string filename = File.PostedFile.FileName; //获得上传文件全路径
int place = filename.LastIndexOf(".") + 1; //获得文件扩展名的位置
string year = DateTime.Now.Year.ToString(); //获得系统时间的年
string month = DateTime.Now.Month.ToString(); //获得系统时间的月
string day = DateTime.Now.Day.ToString(); //获得系统时间的日
string hour = DateTime.Now.Hour.ToString(); //获得系统时间的时
string min = DateTime.Now.Minute.ToString(); //获得系统时间的分
string sec = DateTime.Now.Second.ToString(); //获得系统时间的秒
string mill = DateTime.Now.Millisecond.ToString(); //获得系统时间的毫秒
string extname = filename.Substring(place); //获得上传文件的扩展名
string fullname = year + month + day + hour + min + sec + mill + "." + extname;//重新生成图片名
string imgpath = path + "BgManage/Proct/picture/" + fullname;//上传文件的存放路径
File.PostedFile.SaveAs(imgpath); //文件上传

④ 怎么提交源代码文件上传到qq

怎么提交源代码文件上传到qq具体如下:
1、首先在手机和电脑上同时登陆同一个QQ账号,一般会在电脑端的QQ联系人中有一个【我的设备】的分类,点击展开就会看出【我的手机】;
2、在电脑上点击打开【我的手机】,如果见不到,可以将QQ退出之后再重新登录,然后就会展开聊天对话框,与好友对话是一样的。我们可以直接使用拖拽文件的方式或者是点册敬击文件下面【文件】图标在电脑中查找需哪洞要发送的文件;
3、当添加文件之后一般QQ会默认发送,文件较大等待一段时间发送完成之后就可以在手机的QQ上看到。李姿枯

⑤ jsp+servlet实现文件上传与下载源码

上传:
需要导入两个包:commons-fileupload-1.2.1.jar,commons-io-1.4.jar
import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

/**
* 上传附件
* @author new
*
*/
public class UploadAnnexServlet extends HttpServlet {

private static String path = "";

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request, response);
}

/*
* post处理
* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

path = this.getServletContext().getRealPath("/upload");

try {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload up = new ServletFileUpload(factory);
List<FileItem> ls = up.parseRequest(request);

for (FileItem fileItem : ls) {
if (fileItem.isFormField()) {
String FieldName = fileItem.getFieldName();
//getName()返回的是文件名字 普通域没有文件 返回NULL
// String Name = fileItem.getName();
String Content = fileItem.getString("gbk");
request.setAttribute(FieldName, Content);
} else {

String nm = fileItem.getName().substring(
fileItem.getName().lastIndexOf("\\") + 1);
File mkr = new File(path, nm);
if (mkr.createNewFile()) {
fileItem.write(mkr);//非常方便的方法
}
request.setAttribute("result", "上传文件成功!");
}
}
} catch (Exception e) {
e.printStackTrace();
request.setAttribute("result", "上传失败,请查找原因,重新再试!");
}
request.getRequestDispatcher("/pages/admin/annex-manager.jsp").forward(
request, response);
}

}

下载(i/o流)无需导包:
import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* 下载文件
* @author
*
*/
public class DownloadFilesServlet extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 8594448765428224944L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request, response);
}

/*
* 处理请求
* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String name = request.getParameter("fileName");

System.out.print("dddddddddd:" + name);
// web绝对路径
String path = request.getSession().getServletContext().getRealPath("/");
String savePath = path + "upload";

// 设置为下载application/x-download
response.setContentType("application/x-download");
// 即将下载的文件在服务器上的绝对路径
String filenamedownload = savePath + "/" + name;
// 下载文件时显示的文件保存名称
String filenamedisplay = name;
// 中文编码转换
filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename="
+ filenamedisplay);
try {
java.io.OutputStream os = response.getOutputStream();
java.io.FileInputStream fis = new java.io.FileInputStream(
filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while ((i = fis.read(b)) > 0) {
os.write(b, 0, i);
}
fis.close();
os.flush();
os.close();
} catch (Exception e) {

}

}

}

⑥ asp文件上传:文件上传 源代码

<! #include FILE="upload inc" >谈如 <% dim upload file formName formPath iCount filename fileExt set upload=new upload_ xSoft 建立上传对象 formPath="uploadimages/" 在目录后启戚加(/) if right(formPath )<>"/" then formPath=formPath&"/" iCount= for each formName in upload file 列出所有上传了的文件 set file=upload file(formName) 生成一个文件对象 if file filesize< then response write "<font size= ><br>请先选择你要上传的图片[ <a href=# onclick=history go( )>重新上传</a> ]</font>" response end end if if file filesize> then 含旁启 response write "<font size= ><br>图片大小超过了限制[ <a href=# onclick=history go( )>重新上传</a> ]</font>" response end end if

fileExt=lcase(right(file filename ))

if fileEXT<>" jpg" and fileEXT<>" gif" then response write "<font size= ><br>文件格式只能为jpg和gif格式[ <a href=# onclick=history go( )>重新上传</a> ]</font>" response end end if randomize ranNum=int( *rnd)+ filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&fileExt filename =year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&fileExt if file FileSize> then 如果 FileSize > 说明有文件数据 file SaveAs Server mappath(filename) 保存文件 response write "<script>parent form img value= "&FileName &" </script>"

iCount=iCount+ end if set file=nothing next set upload=nothing 删除此对象

Response Write "<img src= "&" /UpLoad/UpLoadImages/"&FileName &" onload = DrawImage(this) >" response end %>

下面是upload inc的代码

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT> dim upfile_ xSoft_Stream Class upload_ xSoft dim Form File Version Private Sub Class_Initialize dim iStart iFileNameStart iFileNameEnd iEnd vbEnter iFormStart iFormEnd theFile dim strDiv mFormName mFormValue mFileName mFileSize mFilePath iDivLen mStr if Request TotalBytes< then Exit Sub set Form=CreateObject("Scripting Dictionary") set File=CreateObject("Scripting Dictionary") set upfile_ xSoft_Stream=CreateObject("Adodb Stream") upfile_ xSoft_Stream mode= upfile_ xSoft_Stream type= upfile_ xSoft_Stream open upfile_ xSoft_Stream write Request BinaryRead(Request TotalBytes) vbEnter=Chr( )&Chr( ) iDivLen=inString( vbEnter)+ strDiv=subString( iDivLen) iFormStart=iDivLen iFormEnd=inString(iformStart strDiv) while iFormStart < iFormEnd iStart=inString(iFormStart "name=""") iEnd=inString(iStart+ """") mFormName=subString(iStart+ iEnd iStart ) iFileNameStart=inString(iEnd+ "filename=""") if iFileNameStart> and iFileNameStart<iFormEnd then iFileNameEnd=inString(iFileNameStart+ """") mFileName=subString(iFileNameStart+ iFileNameEnd iFileNameStart ) iStart=inString(iFileNameEnd+ vbEnter&vbEnter) iEnd=inString(iStart+ vbEnter&strDiv) if iEnd>iStart then mFileSize=iEnd iStart else mFileSize= end if set theFile=new FileInfo theFile FileName=getFileName(mFileName) theFile FilePath=getFilePath(mFileName) theFile FileSize=mFileSize theFile FileStart=iStart+ theFile FormName=FormName file add mFormName theFile else iStart=inString(iEnd+ vbEnter&vbEnter) iEnd=inString(iStart+ vbEnter&strDiv)

if iEnd>iStart then mFormValue=subString(iStart+ iEnd iStart ) else mFormValue="" end if form Add mFormName mFormValue end if

iFormStart=iformEnd+iDivLen iFormEnd=inString(iformStart strDiv) wend End Sub

Private Function subString(theStart theLen) dim i c stemp upfile_ xSoft_Stream Position=theStart stemp="" for i= to theLen if upfile_ xSoft_Stream EOS then Exit for c=ascB(upfile_ xSoft_Stream Read( )) If c > Then if upfile_ xSoft_Stream EOS then Exit for stemp=stemp&Chr(AscW(ChrB(AscB(upfile_ xSoft_Stream Read( )))&ChrB(c))) i=i+ else stemp=stemp&Chr(c) End If Next subString=stemp End function

Private Function inString(theStart varStr) dim i j bt theLen str InString= Str=toByte(varStr) theLen=LenB(Str) for i=theStart to upfile_ xSoft_Stream Size theLen if i>upfile_ xSoft_Stream size then exit Function upfile_ xSoft_Stream Position=i if AscB(upfile_ xSoft_Stream Read( ))=AscB(midB(Str )) then InString=i for j= to theLen if upfile_ xSoft_Stream EOS then inString= Exit for end if if AscB(upfile_ xSoft_Stream Read( ))<>AscB(MidB(Str j )) then InString= Exit For end if next if InString<> then Exit Function end if next End Function

Private Sub Class_Terminate form RemoveAll file RemoveAll set form=nothing set file=nothing upfile_ xSoft_Stream close set upfile_ xSoft_Stream=nothing End Sub Private function GetFilePath(FullPath) If FullPath <> "" Then GetFilePath = left(FullPath InStrRev(FullPath "")) Else GetFilePath = "" End If End function Private function GetFileName(FullPath) If FullPath <> "" Then GetFileName = mid(FullPath InStrRev(FullPath "")+ ) Else GetFileName = "" End If End function

Private function toByte(Str) dim i iCode c iLow iHigh toByte="" For i= To Len(Str) c=mid(Str i ) iCode =Asc(c) If iCode< Then iCode = iCode + If iCode> Then iLow = Left(Hex(Asc(c)) ) iHigh =Right(Hex(Asc(c)) ) toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh) Else toByte = toByte & chrB(AscB(c)) End If Next End function End Class

lishixin/Article/program/net/201311/14198

热点内容
数据库的字段命名规则 发布:2025-02-05 13:53:16 浏览:683
固定ip自建服务器访问 发布:2025-02-05 13:53:03 浏览:740
快速获取文件夹没文件 发布:2025-02-05 13:52:19 浏览:871
服务器主机如何家用 发布:2025-02-05 13:52:15 浏览:99
安卓应用如何删除自动下载 发布:2025-02-05 13:52:15 浏览:660
c语言switch语句用法 发布:2025-02-05 13:49:16 浏览:936
腾讯缓存不了的动画片怎么办 发布:2025-02-05 13:49:12 浏览:130
access数据库调用 发布:2025-02-05 13:45:01 浏览:49
如何查询服务器所有电脑名 发布:2025-02-05 13:21:38 浏览:150
我的世界ec服务器up主称号怎么获得 发布:2025-02-05 13:21:15 浏览:913