您的位置:首页 > 其它

支持断点续传的多文件上传开发控件

2005-01-12 11:38 232 查看
    应用iWebFile2005控件,能够非常方便的开发多文件上传,  支持大文件上传(大于50M以上)和断点续传的程序.
下载地址: http://www.goldgrid.com/Products/CView.asp?id=82

客户端程序
<%
  Response.buffer=true
  mScriptName="iWebClient.asp"
  mServerName="iWebServer.asp"
  mHttpUrl="http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
  mHttpUrl=Left(mHttpUrl,Len(mHttpUrl)-Len(mScriptName))
  mServerUrl=mHttpUrl & mServerName
%>

<HTML>
<HEAD>
<TITLE>iWebFile2005文档上传下载管理软件 </TITLE>
</HEAD>

<script language="javascript">
    function CheckFileExists(FileName){
 if (iWebFile.WebCheckFile('C://iWebFile//'+FileName)){
  return true;
 }else{
     iWebFile.WebUrl='<%=mServerUrl%>';
            iWebFile.MkDirectory('C://iWebFile');
            if (iWebFile.WebGetFile('C://iWebFile//'+FileName,FileName)){
                return true;
            }else{
                alert(iWebFile.MsgError());
                return false;
     }
 }
    }

    function LoadDocument(FileName){
 iWebFile.WebUrl='<%=mServerUrl%>';
        iWebFile.MkDirectory('C://iWebFile');
        if (iWebFile.WebGetFile('C://iWebFile//'+FileName,FileName)){
            return true;
        }else{
            alert(iWebFile.MsgError());
            return false;
 }
    }

    function OpenDocument(FileName){
        var ClientName,ClientParam,ClientPath,ClientStatus,Result;
 try
 {
     if (LoadDocument(FileName)){
                 ClientName='C://iWebFile//'+FileName;
                 ClientParam='';
                 ClientPath='C://iWebFile';
   ClientStatus=2;
   Result=iWebFile.WebExecute(ClientName,ClientParam,ClientPath,ClientStatus);
    }
 }
 catch(e)
 {
  alert(e.toString()+"/r/n未安装iWebFile插件/r/n请在打开本页面的弹出窗口时,选择[是]按钮,才能正常运行!");
 }
 return;
    }

    function SaveDocument(FileName){
 if (iWebFile.WebCheckFile('C://iWebFile//'+FileName)){
     iWebFile.WebUrl='<%=mServerUrl%>';
            if (iWebFile.WebPutFile('C://iWebFile//'+FileName,FileName)){
         iWebFile.WebDeleteFile('C://iWebFile//'+FileName);
                alert("文件保存成功!");
            }else{
                alert(iWebFile.MsgError());
     }
 }else{
            alert("文件C://iWebFile//"+FileName+"没有找到!");
        }
    }

    function GetServerTime(){
 iWebFile.WebUrl='<%=mServerUrl%>';
        iWebFile.SetMsgByName("FUNCTION","GETSERVERTIME");
        iWebFile.SetMsgByName("STRING",t.value);
        if (iWebFile.MsgSend()){
     st.innerText=iWebFile.GetMsgByName("SERVERTIME");
        }else{
            alert(iWebFile.MsgError());
 }
    }

    function RunServerFunction(){
 iWebFile.WebUrl='<%=mServerUrl%>';
        iWebFile.SetMsgByName("FUNCTION","RUNSERVERFUNCTION");
        iWebFile.SetMsgByName("A",a.value);
        iWebFile.SetMsgByName("B",b.value);
        if (iWebFile.MsgSend()){
     js.innerText=iWebFile.GetMsgByName("RESULT");
        }else{
            alert(iWebFile.MsgError());
 }
    }

    function UpLoadFile(file){
 var FileName;
 //取得需要上传的文件名
 FileName=file.substring(file.lastIndexOf("//")+1);
 //检测文件是否存在
 if (iWebFile.WebCheckFile(file)){
     iWebFile.WebUrl='<%=mServerUrl%>';
     //如果需要保存到其他目录,可以在此设置路径参数.
     //例如:
     //iWebFile.SetMsgByName("FILEPATH","myfile");
     //在服务器上就可以通过GetMsgByName("FILEPATH"),取得文件保存路径myfile,然后进行保存操作

            if (iWebFile.WebPutFile(file,FileName)){
                alert("文件保存成功!");
                location.href="<%=mScriptName%>";
            }else{
                alert(iWebFile.MsgError());
     }
 }else{
            alert("文件"+file+"没有找到!");
        }
    }
    function WebSelectFile(){
 iWebFile.WebUrl='<%=mServerUrl%>';
        if (iWebFile.WebSelectFile()){
                alert("文件保存成功!");
                location.href="<%=mScriptName%>";
        }else{
                alert(iWebFile.MsgError());
 }
    }
    function WebExecute(FileName){
        var ClientName,ClientParam,ClientPath,ClientStatus,Result;
 try
 {
         ClientName=FileName;
         ClientParam='';
         ClientPath='';
   ClientStatus=0;
   Result=iWebFile.WebExecute(ClientName,ClientParam,ClientPath,ClientStatus);
 }
 catch(e)
 {
  alert(e.toString()+"/r/n未安装iWebFile插件/r/n请在打开本页面的弹出窗口时,选择[是]按钮,才能正常运行!");
 }
 return;
    }

    function WebRunServer(FileName){
        var ClientName,ClientParam,ClientPath,ClientStatus,Result;
 try
 {
     if (CheckFileExists(FileName)){
                 ClientName='C://iWebFile//'+FileName;
                 ClientParam='';
                 ClientPath='C://iWebFile';
   ClientStatus=0;
   Result=iWebFile.WebExecute(ClientName,ClientParam,ClientPath,ClientStatus);
    }
 }
 catch(e)
 {
  alert(e.toString()+"/r/n未安装iWebFile插件/r/n请在打开本页面的弹出窗口时,选择[是]按钮,才能正常运行!");
 }
 return;
    }
</script>
<BODY>
<DIV align="center"><font size=5 color=ff0000>iWebFile2005文档上传下载管理软件</font></div><br>
<div  width=80%>
系统特点:<br>
    1、支持大文件上传(大于50M以上)和断点续传;<br>
    2、支持指定文件名上传到服务器上、支持选定多文件上传;<br>
    3、支持下载服务器指定文件到客户端指定目录下;<br>
    4、支持运行客户端应用程序,并能够传递参数给应用程序;<br>
    5、支持下载指定网页或图片并保存到本地目录中。<br>
    6、配合文件下载和运行客户端程序功能,能够达到运行服务器上的应用程序的目的;<br>
    7、配合文件下载和运行客户端程序和指定文件上传功能,能够达到将直接修改服务器文件的目的;<br>
    8、支持强大的通讯功能,可以随时和服务器进行数据传递;<br>
    9、支持asp,jsp,php,.net等多种平台;<br>
    10、本软件非常适合网络文档的管理。<br>
<br></div>
<DIV align="center">
<table border=1 width=80% >
   <tr>
       <td colspan=3 bgcolor=menu>(标准方式)文件上传功能演示</td>
   </tr>
   <tr>
       <td colspan=2 nowrap>文件名:<input id=fa type=file value="" style=width:80%></td>
       <td><input type=button onclick="UpLoadFile(fa.value)" value="上传文档"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>(指定方式)文件上传功能演示</td>
   </tr>
   <tr>
       <td colspan=2 nowrap>文件名:<input id=fb type=text value=""  style=width:80%></td>
       <td><input type=button onclick="UpLoadFile(fb.value)" value="上传文档"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>(选定多文件)上传功能演示</td>
   </tr>
   <tr>
       <td colspan=2 nowrap>请按右边的[上传多文档]按钮,选择你要上传的文件.</td>
       <td><input type=button onclick="WebSelectFile();" value="上传多文档"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>打开本地程序功能演示</td>
   </tr>
   <tr>
       <td colspan=2 nowrap>请按右边的按钮.</td>
       <td><input type=button onclick="WebExecute('calc.exe');" value="运行计算器"></td>
   </tr>
   <tr>
       <td colspan=2 nowrap>请按右边的按钮.</td>
       <td><input type=button onclick="WebExecute('mspaint.exe');" value="运行画笔"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>运行服务器上的程序功能演示</td>
   </tr>
   <tr>
       <td colspan=2 nowrap>请按右边的按钮.</td>
       <td><input type=button onclick="WebRunServer('Test.exe');" value="运行远程程序"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>交互通讯功能演示</td>
   </tr>
   <tr>
       <td><div id=st> </div></td>
       <td colspan=2><input id=t type=text value="服务器时间是:" size=9><input type=button onclick="GetServerTime()" value="取服务器时间"></td>
   </tr>
   <tr>
       <td><div id=js> </div></td>
       <td colspan=2><input id=a type=text value="4" size=3>*<input id=b type=text value="6" size=3><input type=button onclick="RunServerFunction()" value="让服务器计算"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>文件处理功能演示</td>
   </tr>

<%
  DBStr="DBQ=" & Server.mappath("FileName.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
  Set DBDemo=Server.CreateObject("ADODB.Connection")
  DBDemo.Open DBStr

  Set TbMainRs=Server.CreateObject("ADODB.RecordSet")       '创建页面显示
  TbMainRs.Open "select * from FileList order by FileID desc",DBDemo,1,1   '打开数据库
  Do While Not TbMainRs.Eof              '当没有显示到最后一条记录或没有显示RowCount记录时

%>
   <tr>
       <td width=80%><%=TbMainRs("FileName")%> </td>
       <td width=80><input type=button onclick="OpenDocument('<%=TbMainRs("FileName")%>')" value="打开文档"></td>
       <td width=80><input type=button onclick="SaveDocument('<%=TbMainRs("FileName")%>')" value="保存文档"></td>
   </tr>
<%
     TbMainRs.MoveNext
  Loop
  TbMainRs.Close
  Set TbMainRs=Nothing
  DBDemo.Close
  Set DBDemo=Nothing
%>
   <tr>
       <td width=80%>MOD00001.DOC</td>
       <td width=80><input type=button onclick="OpenDocument('MOD00001.DOC')" value="打开文档"></td>
       <td width=80><input type=button onclick="SaveDocument('MOD00001.DOC')" value="保存文档"></td>
   </tr>
   <tr>
       <td>Mod00001.xls</td>
       <td><input type=button onclick="OpenDocument('Mod
a709
00001.xls')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('Mod00001.xls')" value="保存文档"></td>
   </tr>
   <tr>
       <td>金格公司演示文档.ppt</td>
       <td><input type=button onclick="OpenDocument('金格公司演示文档.ppt')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('金格公司演示文档.ppt')" value="保存文档"></td>
   </tr>
   <tr>
       <td>DBstep.mdb</td>
       <td><input type=button onclick="OpenDocument('DBstep.mdb')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('DBstep.mdb')" value="保存文档"></td>
   </tr>
   <tr>
       <td>传真资料.tif</td>
       <td><input type=button onclick="OpenDocument('传真资料.tif')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('传真资料.tif')" value="保存文档"></td>
   </tr>
   <tr>
       <td>名片.bmp</td>
       <td><input type=button onclick="OpenDocument('名片.bmp')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('名片.bmp')" value="保存文档"></td>
   </tr>
   <tr>
       <td>普通文本文件.txt</td>
       <td><input type=button onclick="OpenDocument('普通文本文件.txt')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('普通文本文件.txt')" value="保存文档"></td>
   </tr>
   <tr>
       <td>goldgridLogo.psd</td>
       <td><input type=button onclick="OpenDocument('goldgridLogo.psd')" value="打开文档"></td>
       <td><input type=button onclick="SaveDocument('goldgridLogo.psd')" value="保存文档"></td>
   </tr>
   <tr>
       <td colspan=3 bgcolor=menu>
 <OBJECT id="iWebFile" classid="clsid:074106C0-5E71-4151-9CE8-9B024485B58F" codebase="iWebFile2005.ocx#version=5,6,0,4" width=100% height=24 >
 </OBJECT>
       </td>
   </tr>
</table>
</div>

</BODY>
</HTML>

服务器程序
<%
function SaveFileName(vFileName)
  DBStr="DBQ=" & Server.mappath("FileName.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
  Set DBDemo=Server.CreateObject("ADODB.Connection")
  DBDemo.Open DBStr
  DBSql = "select * from FileList where FileName = '" & vFileName & "'"
  Set TbMain=Server.CreateObject("ADODB.RecordSet")       '创建页面显示
  TbMain.Open DBSql,DBDemo,1,3   '打开数据库
  if TbMain.eof then
     TbMain.AddNew
  end if
  TbMain("FileName")=vFileName
  TbMain.Update
  TbMain.Close
  Set TbMain=Nothing
  DBDemo.Close
  Set DBDemo=Nothing
  SaveFileName=True
end function

Set FileObj=Server.CreateObject("DBstep.MsgServer2000")  '创建信息包对象
if (FileObj.GetMsgByName("DBSTEP")="DBSTEP") then  '如果是合法的信息包
  mOption=FileObj.GetMsgByName("OPTION")   '取得操作信息
  mFilePath=Server.mappath(".") & "/Document"
  select case mOption
    case "WEBGETFILE"      '打开服务器里的文件
             mFileName=FileObj.GetMsgByName("FILENAME")  '取得文档名
      if FileObj.MsgFileLoad(mFilePath & "/" & mFileName) then '调入文档
        FileObj.SetMsgByName "STATUS","打开成功!" '设置状态信息
        FileObj.MsgError=""    '清除错误信息
      else
        FileObj.MsgError="打开失败!"   '设置错误信息
      end if
    case "WEBPUTFILE"      '保存文件在服务器里
             mFileName=FileObj.GetMsgByName("FILENAME")  '取得文档名
             mCommand=FileObj.GetMsgByName("COMMAND")
      select case mCommand
  case "BEGIN"
                     mFilePoint=FileObj.LoadFilePoint(mFilePath & "/" & mFileName)
       FileObj.SetMsgByName "FILEPOINT",mFilePoint
              FileObj.MsgError=""       '清除错误信息
  case "SAVEFILE"
       mIndex=FileObj.GetMsgByName("INDEX") 
       mTotal=FileObj.GetMsgByName("TOTAL") 
       if FileObj.MsgFileSave(mFilePath & "/" & mFileName & "." & mIndex) then '保存临时文档
   if FileObj.SaveFilePoint(mFilePath & "/" & mFileName,mIndex) then
           FileObj.MsgError=""      '清除错误信息
   else
    FileObj.MsgError="保存状态文件失败!"    '清除错误信息
   end if
       else
          FileObj.MsgError="保存断点文件失败!"     '设置错误信息
       end if
  case "END"
       mIndex=FileObj.GetMsgByName("INDEX") 
       mTotal=FileObj.GetMsgByName("TOTAL") 
       if FileObj.SaveFromFile(mFilePath & "/" & mFileName,mTotal) then  '保存文档
                 SaveFileName mFileName
          FileObj.MsgError=""       '清除错误信息
       else
          FileObj.MsgError="合成文件失败!"     '设置错误信息
       end if
      end select
      FileObj.MsgFileClear    '清除文档内容
    case "MSGSEND"
             mFunction=FileObj.GetMsgByName("FUNCTION")  '取得功能名称
      if mFunction="GETSERVERTIME" then   '处理取得服务器时间请求
  mString=FileObj.GetMsgByName("STRING")
         mDateTime=CDate(now())
  FileObj.SetMsgByName "SERVERTIME",mString  & mDateTime
         FileObj.MsgError=""    '清除错误信息
      end if
      if mFunction="RUNSERVERFUNCTION" then  '处理取得服务器计算请求
  mA=FileObj.GetMsgByName("A")
  mB=FileObj.GetMsgByName("B")
         mC=Cint(mA)*Cint(mB)
  FileObj.SetMsgByName "RESULT",CStr(mC)
         FileObj.MsgError=""    '清除错误信息
      end if
    case else
      FileObj.SetMsgByName "STATUS","Option错误:" & mOption '设置状态信息
      FileObj.MsgError="Option错误:" & mOption     '设置错误信息
  end select
else
  FileObj.MsgError="客户端发送数据包错误!"
  FileObj.MsgTextClear
  FileObj.MsgFileClear
end If

Response.BinaryWrite FileObj.MsgVariant
Set FileObj=nothing

%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息