人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

不用組件上載文件代碼具體例子

不用組件上載文件代碼具體例子

更新時間:2021-01-01 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

不用組件上載文件代碼具體例子

下面的第一個例子為只是將客戶端的文件上傳到服務(wù)端的例子
第二個例子為將文件內(nèi)容保存入數(shù)據(jù)庫中。
文件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 & "
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 & "
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">

    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 type="CHECKBOX" name="Check1" Checked></TD></TR>
  <TR><TD>Password</TD><TD><input type="PASSWORD" name="PASSWORD"></TD></TR>
  <TR><TD>Comments</TD><TD><input size="60" name="Comments" value="Some comments."></TD></TR>
  <TR><TD>Description</TD><TD><textarea cols="60" rows="8" name="Description">Some long text of any size - without 80k limit of ASP Request.Form("...").</textarea></TD></TR>
 </form>
</Table>
<HR>?%=ResultHTML%>
<Script>
 var nfiles = 2;
 function Expand(){
  nfiles++
  files.insertAdjacentHTML('BeforeEnd','<BR>File?+nfiles+'??input type="file" name="File'+nfiles+'">');
  
  return false
 }
</Script>
<%=Foot%>

文件fdbutl.asp將文件內(nèi)容保存如數(shù)據(jù)庫中
<%'upload.inc, contains GetUpload function, Required for upload - only the one file%>
<!--#INCLUDE FILE="fupload.inc"-->
<%'format.inc, contains head and Foot function, optional.%>
<!--#INCLUDE FILE="fformat.inc"-->
<%=Head("Sample database 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><TD></TD><TD Align=Right><input type="submit" Name="Action" value="Upload the file >>"></TD></TR>
  <TR><TD>File to upload</TD><TD><input type="file" name="DBFile"></TD></TR>
  <TR><TD>Title</TD><TD><input size="60" name="Title" value="Title of the file."></TD></TR>
  <TR><TD>Description</TD><TD><textarea cols="60" rows="8" name="Description">Type description of the file.</textarea></TD></TR>
 </form>
</Table>

<%=Foot%>

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
'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 = 200


If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 'Request method must be "POST" for get the fields
 '*************************************************  Main Upload - start
  Dim Fields
 ' on error resume next
  '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.String - File1 field converted to a string
  'Fields("File1").Value.ByteArray - File1 field as safearray to store in binary RS field or file
  'Fields("Comments").Value.String - value of Comments field

  If Err = 0 Then 'Upload was OK
   'Saves fields to the database and returns result to the client.
   Response.Write DBSaveUpload(Fields)
  Else 'Error in upload. Write the error
   Response.Write Err.Description
  End If
  On Error GoTo 0
  Fields = Empty 'Clear the variable
 '*************************************************  Main Upload - end
End If 'Request method must be "POST"


function DBSaveUpload(Fields)
 dim Conn, RS
 Set Conn = GetConnection
 Set RS = Server.CreateObject("ADODB.Recordset")
 RS.Open "Upload", Conn, 2, 2
 RS.AddNew
  RS("UploadDT") = Now()

  RS("RemoteIP") = Request.ServerVariables("REMOTE_ADDR")
  RS("ContentType") = Fields("DBFile").ContentType
  RS("SouceFileName") = Fields("DBFile").FileName

  RS("Description") = BinaryToString(Fields("Description").Value)
  RS("Title") = BinaryToString(Fields("Title").Value)
  RS("Data").AppendChunk Fields("DBFile").Value
 RS.Update
 RS.Close
 Conn.Close
 DBSaveUpload = "
File <b>" & Fields("DBFile").FileName & "</b>, length : <b>" & Fields("DBFile").Length & " B</b> was saved to the database. "
end function

function GetConnection()
 dim Conn, AuthConnectionString
 Set Conn = Server.CreateObject("ADODB.Connection")
 'MDB connection
 AuthConnectionString = "DBQ=" & Server.MapPath(".") & "\fupload.mdb;DefaultDir=" & Server.MapPath("/") & ";" & _
   "Driver={Microsoft Access Driver (*.mdb)}; DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5;UID=;"
 Conn.open AuthConnectionString
 'SQL connection
 'Simply change connection and create table to upload to MS SQL
' Conn.Provider = "SQLOLEDB"
' Conn.Open "Server=(Local);Database=Auth", "sa", "password"
  set GetConnection = Conn
end function

function CreateUploadTable(Conn)
dim SQL
SQL = SQL & "CREATE TABLE Upload ("
SQL = SQL & "  UploadID int IDENTITY (1, 1) NOT NULL ,"
SQL = SQL & "  UploadDT datetime NULL ,"
SQL = SQL & "  RemoteIP char (15) NULL ,"
SQL = SQL & "  ContentType char (64) NULL ,"
SQL = SQL & "  SouceFileName varchar (255) NULL ,"
SQL = SQL & "  Title varchar (255) NULL ,"
SQL = SQL & "  Description text NULL ,"
SQL = SQL & "  Data image NULL "
SQL = SQL & ")"
Conn.Execute SQL
end function
</SCRIPT>

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 邵武市| 华宁县| 定边县| 巴青县| 肇东市| 柯坪县| 东明县| 芜湖县| 台安县| 石楼县| 西贡区| 绥化市| 靖远县| 比如县| 当涂县| 两当县| 那曲县| 云霄县| 奉新县| 碌曲县| 营口市| 鞍山市| 砀山县| 惠东县| 酒泉市| 兰坪| 当涂县| 连城县| 获嘉县| 武胜县| 巩留县| 苗栗市| 佛坪县| 库伦旗| 徐汇区| 六枝特区| 屯昌县| 商河县| 尼勒克县| 祥云县| 共和县|