top
Loading...
不用組件實現上載功能(英文NT)

'---- file name /upaoad.asp/

<%
Public Function BuildUploadRequest(strRequestBin)
Dim PosBeg, PosEnd, boundary, boundaryPos
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,strRequestBin,getByteString(chr(13)))
boundary = MidB(strRequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,strRequestBin,boundary)

'Get all data inside the boundaries
Do until (boundaryPos = InstrB(strRequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")

Dim Pos, Name
'Get an object name
Pos = InstrB(boundaryPos,strRequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,strRequestBin,getByteString("name="))
PosBeg = Pos + Len("name=") + 1
PosEnd = InstrB(PosBeg,strRequestBin,getByteString(chr(34)))
Name = getString(MidB(strRequestBin,PosBeg,PosEnd-PosBeg))

Dim PosFile, PosBound, ContentType, Value
'Test if object is of file type
PosFile = InstrB(BoundaryPos,strRequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,strRequestBin,boundary)

If PosFile <> 0 AND PosFile < PosBound Then
'Get FilePathName of the file
PosBeg = PosFile + Len("filename=") + 1
PosEnd = InstrB(PosBeg,strRequestBin,getByteString(chr(34)))
FilePathName = getString(MidB(strRequestBin,PosBeg,PosEnd-PosBeg))

'Add filename(with path) to dictionary object
UploadControl.Add "FilePathName", FilePathName

'Get Content-Type of the file
Pos = InstrB(PosEnd,strRequestBin,getByteString("Content-Type:"))
PosBeg = Pos + Len("Content-Type:") + 1
PosEnd = InstrB(PosBeg,strRequestBin,getByteString(chr(13)))
ContentType = getString(MidB(strRequestBin,PosBeg,PosEnd-PosBeg))

'Add content-type to dictionary object
UploadControl.Add "ContentType",ContentType

'Get content of object
PosBeg = PosEnd + 4
PosEnd = InstrB(PosBeg,strRequestBin,boundary)-2
Value = MidB(strRequestBin,PosBeg,PosEnd-PosBeg)
Else
'Get content of object
Pos = InstrB(Pos,strRequestBin,getByteString(chr(13)))
PosBeg = Pos + 4
PosEnd = InstrB(PosBeg,strRequestBin,boundary)-2
Value = getString(MidB(strRequestBin,PosBeg,PosEnd-PosBeg))
End If

'Add content to dictionary object
UploadControl.Add "Value" , Value

'Add dictionary object to main dictionary
Set UploadRequest(Name) = UploadControl

'Loop to next object
BoundaryPos = InstrB(BoundaryPos+LenB(boundary),strRequestBin,boundary)
Loop
End Function

'String to byte string conversion
Public Function getByteString(strString)
Dim intCount

getByteString = ""

For intCount = 1 to Len(strString)
getByteString = getByteString & chrB(AscB(Mid(strString,intCount,1)))
Next
End Function

'Byte string to string conversion
Public Function getString(strString)
Dim intCount

getString = ""

For intCount = 1 to LenB(strString)
getString = getString & chr(AscB(MidB(strString,intCount,1)))
Next
End Function
%>


'---- file name /handld_upload.asp

<% Option Explicit %>

<%
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
Const IMAGE_SIZE = "width=""200"" height=""150"""
Dim UploadRequest
Set UploadRequest = Server.CreateObject("Scripting.Dictionary")

Dim byteCount, RequestBin
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)

BuildUploadRequest RequestBin

Dim saveURL, goURL, filepathname, value, filename
'---- save path
'saveURL = UploadRequest.Item("saveURL").Item("Value")
saveURL = "/"

'---- jump to file path when finish upload
goURL = UploadRequest.Item("goURL").Item("Value")

filepathname = UploadRequest.Item("my_file").Item("FilePathName")
value = UploadRequest.Item("my_file").Item("Value")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,""))

'---- debug
'Response.Write saveURL&"**"&goURL&"**"&filepathname
'Response.Write "**"&filename
'Response.End

Dim fso, MyFile, i
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(Server.mappath(saveURL) & "") Then
RecMkDir(Server.mappath(saveURL) & "")
End If
Set MyFile = fso.CreateTextFile(Server.mappath(saveURL) & "" & filename)

For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next

MyFile.Close

Session("StoredFile") = filename
Session("strImage") = "<img src='" & saveURL & filename & "'" & IMAGE_SIZE & " border=1 bordercolor=#0000FF>"

Response.Redirect goURL
%>
<!--#include file="upload.asp"-->

'---- file name /test.asp/
<% Option Explicit %>

<%
On Error Resume Next
Response.Expires = 0
Response.AddHeader "Pragma", "no-cache"

Dim thisFile
thisFile = Right(Request.ServerVariables("PATH_INFO"),Len(Request.ServerVariables("PATH_INFO"))-InStrRev(Request.ServerVariables("PATH_INFO"), "/"))

If Request("imageCancel") <> "" Then
Session("StoredFile") = ""
Session("strImage") = ""
End If
%>
<html>
<head>
<title>Corp2Net.com</title>
<script language="JavaScript" src="/admin.js"></script>
<script language="JavaScript">
<!--
function UpLoad(obj)
{
if (obj.my_file.value.length < 7)
return false;
return true;
}
// -->
</script>
<body link=<%= COLOR_NL_1 %> alink=<%= COLOR_AL_1 %> vlink=<%= COLOR_VL_1 %> bgcolor=<%= COLOR_BG_1 %>>
<font color="<%= C_WD_CONTENT_4 %>">
Only upload <b>*.jpg</b> or <b>*.gif</b> file!
<br>
Otherwise, image may not show correctly!
</font>
<center>
<table>
<% If ( Len(Session("strImage")) > 0 ) Then %>
<tr>
<td>
<table border="1" bordercolor="<%= C_WD_T_BORDER %>" cellspacing="0" cellpadding="0" <%= IMAGE_SIZE %>>
<tr>
<td><%= Session("strImage") %></td>
</tr>
</table>
</td>
</tr>
<% Else %>
<tr>
<td>
<table border="1" bordercolor="<%= C_WD_T_BORDER %>" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="top">
<table cellspacing="0" cellpadding="0" border="0" <%= IMAGE_SIZE %>>
<tr>
<td colspan="2"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>"><b>Upload / preview image:</b></font></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td valign="top" nowrap><font class="e-foot" color="<%= C_WD_CONTENT_4 %>"><b>Step 1:</b></font></td>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>">Prepare an image with 72 dpi resolution.</font></td>
</tr>
<tr>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>"><b>Step 2:</b></font></td>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>">Select your image file</font></td>
</tr>
<tr>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>"><b>Step 3:</b></font></td>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>">Press "Upload" button</font></td>
</tr>
<tr>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>"><b>Step 4:</b></font></td>
<td valign="top"><font class="e-foot" color="<%= C_WD_CONTENT_4 %>">Continue <b>OR</b> repeat <b>Step 1-3</b> to change the image</font></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<% End If %>
</table>
</center>

<form method="POST" enctype="multipart/form-data" action="handle_upload.asp" onSubmit="return UpLoad(this)" id=form1 name=form1>
<input type="hidden" name="saveURL" value="<%= WEB_TEMP_PATH %>">
<input type="hidden" name="goURL" value="<%= Request.ServerVariables("PATH_INFO") %>">
<input class="btn" type="file" name="my_file">
<input class="btn" type="submit" name="submit" value="Upload" >
</form>

<form action="<%= thisFile %>" id=form2 name=form2>
<input class="btn" type="submit" name="imageCancel" value="Press Here To Cancel Image!">
<br> <br>
<input class="btn" type="submit" value="Finish!" onClick="window.opener.focus();window.close();" id=submit1 name=submit1>
</form>
</body>
</html>

北斗有巢氏 有巢氏北斗