以前收集的一些資料---不用組件上傳檔案代碼具體例子

來源:互聯網
上載者:User
下面的第一個例子為只是將用戶端的檔案上傳到服務端的例子
第二個例子為將檔案內容儲存入資料庫中。
檔案fupload.asp
<%
dim ResultHTML
'Some value greater than default of 60s (According to upload size.)
'The maximum speed is about 100kB/s for IIS4, P200 and local upload, 4kB/s for modem users.
Server.ScriptTimeout = 400

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 'Request method must be "POST" for get the fields
'  BeginTimer 'Starts timer.
  '*************************************************   Main Upload - start
    Dim Fields
'    on error resume next
    'Set upload limit to 10M
    UploadSizeLimit = 10000000

    'Gets uploaded fields
    Set Fields = GetUpload()

    'There are all of form fields in the Fields object. Example :
    'Fields("File1").ContentType - content type of File1 field
    'Fields("File1").Value - Binary value of File1 field
    ResultHTML = ""
    If Err = 0 Then 'Upload was OK
      'Write statistics about upload
      dim Field
      For Each Field In Fields.Items
        ResultHTML = ResultHTML & "<br>Field : <b>" & LogF(Field.name) & "</b>, Length : <b>" & LogFn(Field.Length) & "</b>, Content-Type : <b>" & LogF(Field.ContentType) & "</b>, SourceFileName :?b>" & LogF(Field.FileName) & "</b>"
      Next

      'Saves the fields to the disk, writes result to the client and writes log.
      'See utils.inc. You can change the function to save the files to another location.
      ResultHTML = ResultHTML & "<BR>" & SaveUpload(Fields, Server.MapPath("."), LogFolder)
    Else 'Error in upload. Write the error
      ResultHTML = ResultHTML & "<br>Error : " & Err.Description
    End If
    On Error GoTo 0
    Fields = Empty 'Clear the variable
  '*************************************************   Main Upload - end
'  EndTimer 'Writes info about consumed time.
End If 'Request method must be "POST"

%>


<%'upload.inc, contains GetUpload function, Required for upload - only the one file%>
<!--#INCLUDE FILE="fupload.inc"-->
<%'utils.inc, contains SaveUpload function%>
<!--#INCLUDE FILE="futils.inc"-->
<%'format.inc, contains head and Foot function, optional.%>
<!--#INCLUDE FILE="fformat.inc"-->
<%=Head("Sample multiple binary files upload via ASP", "Demonstrates using of the ByteArray class for working with binary data from Request.BinaryRead.")%>

<Table>
  <form method=post ENCTYPE="multipart/form-data">
    <TR BGColor=Silver><TD></TD><TD Align=Right><input type="submit" Name="Action" value="Upload the files >>"></TD></TR>
    <TR><TD ColSpan=2>
      <Table Width=100% Border=0 cellpadding=0 cellspacing=0><tr><TD>
      <Div ID=files>
        File???input type="file" name="File1"><br>
        File???input type="file" name="File2">
      </Div>
      <TD><TD Align=right VAlign=top>
        <A style=cursor:hand onclick=return(Expand())><Font COlor=Blue><U>add a file</U></Font></a>
      </TD></TR></Table>
    </TD></TR>
    <TR><TD>Checkbox</TD><TD><input



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。