Upfile. asp
<! -- # Include file = "Upload. Inc" -->
<HTML>
<Head>
<Title> File Upload </title>
</Head>
<Body>
<%
Dim Arr (3)
Dim upload, file, formname, formpath, icount, filename, fileext, I
Set upload = new upload_5xsoft 'create an upload object
Formpath = upload. Form ("filepath ")
'Add (/) after the Directory (/)
If right (formpath, 1) <> "/" then formpath = formpath &"/"
Icount = 0
I = 0
For each formname in upload. file' list all uploaded files
Set file = upload. File (formname) 'to generate a file object
If file. filesize <0 then
Response. write "<font size = 2> select the image you want to upload [<a href = # onclick = history. go (-1)> re-upload </a>] </font>"
Response. End
End if
If file. filesize> 100000 then
Response. write "<font size = 2> the image size exceeds the limit [<a href = # onclick = history. go (-1)> re-upload </a>] </font>"
Response. End
End if
If fileext <> ". GIF" and fileext <> ". jpg" then
Response. the write "<font size = 2> file format is incorrect [<a href = # onclick = history. go (-1)> re-upload </a>] </font>"
Response. End
End if
Fileext = lcase (right (file. filename, 4 ))
Filename = formpath & year (now) & month (now) & Day (now) & hour (now) & minute (now) & Second (now) & file. filename
Arr (I) = filename
I = I + 1
If file. filesize> 0 then' if filesize> 0, file data exists.
File. saveas server. mappath (filename) 'save the file
'Response. Write File. filepath & file. filename & "(" & file. filesize & ") =>" & formpath & file. filename & "success! <Br>"
Icount = icount + 1
End if
Set file = nothing
Next
If instr (ARR (0 ),". ") = 0 and instr (ARR (1 ),". ") = 0 and instr (ARR (2 ),". ") = 0 then
Response. write "<font size = 2> select the image you want to upload [<a href = # onclick = history. go (-1)> re-upload </a>] </font>"
Response. End
End if
If instr (ARR (0), ".") <> 0 then
Response. Write "<SCRIPT> opener.doc ument. Forms [0]. myface. value = '" & Arr (0) & "' </SCRIPT>"
Else
Response. Write "<SCRIPT> opener.doc ument. Forms [0]. myface. value = '</SCRIPT>"
End if
If instr (ARR (1), ".") <> 0 then
Response. Write "<SCRIPT> opener.doc ument. Forms [0]. myface1.value = '" & Arr (1) & "' </SCRIPT>"
Else
Response. Write "<SCRIPT> opener.doc ument. Forms [0]. myface1.value = '</SCRIPT>"
End if
If instr (ARR (2), ".") <> 0 then
Response. Write "<SCRIPT> opener.doc ument. Forms [0]. myface2.value = '" & Arr (2) & "' </SCRIPT>"
Else
Response. Write "<SCRIPT> opener.doc ument. Forms [0]. myface2.value = '</SCRIPT>"
End if
Set upload = nothing 'Delete this object
Session ("upface") = "done"
Htmend icount & "File Upload is complete! "
Sub htmend (MSG)
Set upload = nothing
Response. write "<HTML> Response. End
End sub
%>
</Body>
</Html>
This article comes from web development network Original article link: http://www.cncms.com.cn/asp/5006_3.htm