Browser----One, problem introduced
----in the current management information system, more advanced have adopted the browser/server model, in this model will involve the client and server side of the information interaction problem, from server to client information transfer technology has been more mature, here mainly discusses from the client to the server side of the file upload problem, Based on Microsoft's IE4.0, IIS4.0, ASP (Active Server Page), and standard HTML languages.
----Two, the realization method
----In an ASP page, use the form element in HTML to implement it.
----in the syntax of a FORM element, enctype indicates the format in which the data is submitted, and methods indicate the method of submission (Get/post). The "Multipart/form-data" format is supported in both IE4.0 and later versions, and the corresponding method must be post, indicating that the file is to be uploaded to the server. Of course, at the same time on the server to the corresponding Web site to make the property writable. Here is an example:
< form enctype= "Multipart/form-data"
Action= "Http://dev_d/upload/post/cpshost.dll?"
Publish?http://dev_d/upload/useruploadaction.asp "
Method=post Id=form2 Name=form2 >
1. Press the Browse button and
Choose a File to upload from your computer.
< br >< input type= "file" Id=file1 name=file1 >
2. Upload the file.
< br >< input Type=hidden size=80 name= "TargetUrl"
Value=http://dev_d/upload/post >
< input type=submit value= ' Upload '
Id=submit1 name=submit1 >
</form >
----three, the realization element
1 form of the enctype= "Multipart/form-data".
2 form of action= "(Userurl)/cpshost.dll?" PUBLISH?
(Userurl)/useruploadaction.asp ".
----Description: Cpshost.dll is a dynamic link file for file uploads, followed by publish parameters, and (Userurl) refers to the complete URL address, such as: Http://dev_d/upload. If there is no parameter after publish, upload file is completed, simply return the file has been uploaded, if the publish after the full URL of the ASP file, you can use ASP to deal with the file upload other operations, such as modify the corresponding database data. You can use Request.Form ("Variable") in an ASP file to access the appropriate parameters. For upload files, variable has four possible values: FileName file name (excluding suffix), fileextention file suffix (including "."), FilePath upload file saved server-side path, FileSize the byte size of uploaded file.
The method----3 form must be a post.
----4 form must have an INPUT element, and the input property type= "file".
----NOTE: If you want to upload more than one file, you can have multiple input elements, but at least one valid file, or there will be an error.
The----system automatically generates a text area and a "Browse ..." button to enter the file path name directly in the text area, or click the "Browse ..." button to select a file from the file dialog box.
----5 form must have an implied (i.e. Type=hidden) input element, and the properties of input name= "TargetUrl", attributes
----value= "(Userurl)" (Userurl) is the URL address where the file is saved.
----Note: The URL address attribute of the location where the file is saved must be set to writable or it will return a permission that is not written for this URL address.
----6 form must have a submit button, which is the property of input type= "submit", which is the upload button. or call the Submit method of this form in other related events. But the two methods are essentially the same, except that the method call can also add other processing code before uploading, such as data validation checks.
----Four, complete examples
----1 User upload file page userupload.asp
<% response.expires=0% >
< HTML >
< head >
< META name= "generator"
Content= "Microsoft Visual Studio 6.0" >
< BODY >
< form enctype= "Multipart/form-data"
Action= "Http://dev_d/upload/post/cpshost.dll?"
Publish?http://dev_d/upload/useruploadaction.asp "
Method=post Id=form2 Name=form2 >
< table border=0 Cellspacing=3 cellpadding=3 >
< tr >
< TD Valign=top >< span >1. </span >
< TD >press The Browse button and choose a File to upload from your computer.
< br >< input type= "file" Id=file1 name=file1 >
< br >< input type= "file" Id=file2 name=file2 >
</td >
< tr >
< TD valign=top >< SPAN >2. </span >
< TD >upload the file.
< br >< input Type=hidden size=80 name= "TargetUrl" value= "Http://dev_d/upload/post" >
< input type=submit value= ' Upload '
Id=submit1 name=submit1 >
</td >
</table >
</form >
</body >
2 User Upload file processing page useruploadaction.asp
<% Response.Buffer = TRUE% >
<% response.expires=0% >
< HTML >
< BODY >
< H3 >upload status:< BR >
< span style= "Color:gray" >< HR >
<% for I = 1 to Request.Form ("FileName"). Count
Response.Write "uploaded File: < B >" &
Request.Form ("FileName") (I) &
Request.Form ("Fileextention") (I) & "</b >< BR >"
Response.Write "Server Path: < B >" &
Request.Form ("FilePath") (I) & "</b >< BR >"
Response.Write "Size: < B >"
& Request.Form ("FileSize") (I)
& "bytes</b >< br >"
Next
FileName = Request.Form ("FilePath") (1) &
Request.Form ("FileName") (1) &
Request.Form ("Fileextention") (1)
% >
< hr >< br >
<% if Request.Form ("FilePath"). Count = 0 Then
Response.Write ("No file was received.")
Response.End
Else
Response.Write (filename+ "File was received.")
End If% >
</span >
</body >