不用组件实现上载功能(2)

'---- file name /handld_upload.asp

1 Option Explicit 
 1   
 2Response.Expires=0   
 3Response.Buffer = TRUE   
 4Response.Clear   
 5Const IMAGE_SIZE = "width=""200"" height=""150"""   
 6Dim UploadRequest   
 7Set UploadRequest = Server.CreateObject("Scripting.Dictionary")   
 8  
 9Dim byteCount, RequestBin   
10byteCount = Request.TotalBytes   
11RequestBin = Request.BinaryRead(byteCount)   
12  
13BuildUploadRequest RequestBin   
14  
15Dim saveURL, goURL, filepathname, value, filename   
16'---- save path   
17'saveURL = UploadRequest.Item("saveURL").Item("Value")   
18saveURL = "/"   
19  
20'---- jump to file path when finish upload   
21goURL = UploadRequest.Item("goURL").Item("Value")   
22  
23filepathname = UploadRequest.Item("my_file").Item("FilePathName")   
24value = UploadRequest.Item("my_file").Item("Value")   
25filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))   
26  
27'---- debug   
28'Response.Write saveURL&"**"&goURL&"**"&filepathname   
29'Response.Write "**"&filename   
30'Response.End   
31  
32Dim fso, MyFile, i   
33Set fso = Server.CreateObject("Scripting.FileSystemObject")   
34If NOT fso.FolderExists(Server.mappath(saveURL) & "\") Then   
35RecMkDir(Server.mappath(saveURL) & "\")   
36End If   
37Set MyFile = fso.CreateTextFile(Server.mappath(saveURL) & "\" & filename)   
38  
39For i = 1 to LenB(value)   
40MyFile.Write chr(AscB(MidB(value,i,1)))   
41Next   
42  
43MyFile.Close   
44  
45Session("StoredFile") = filename   
46Session("strImage") = "

<img "="" &="" border="1" bordercolor="#0000FF" image_size="" src='" &amp; saveURL &amp; filename &amp; "'/>

1"   
2  
3Response.Redirect goURL   

'---- file name /test.asp/

1 Option Explicit 
 1   
 2On Error Resume Next   
 3Response.Expires = 0   
 4Response.AddHeader "Pragma", "no-cache"   
 5  
 6Dim thisFile   
 7thisFile = Right(Request.ServerVariables("PATH_INFO"),Len(Request.ServerVariables("PATH_INFO"))-InStrRev(Request.ServerVariables("PATH_INFO"), "/"))   
 8  
 9If Request("imageCancel") <> "" Then   
10Session("StoredFile") = ""   
11Session("strImage") = ""   
12End If   
 1<html>
 2<head>
 3<title>Corp2Net.com</title>
 4<script language="JavaScript" src="/admin.js"></script>
 5<script language="JavaScript">   
 6<!--   
 7function UpLoad(obj)   
 8{   
 9if (obj.my_file.value.length < 7)   
10return false;   
11return true;   
12}   
13// -->   
14</script>
15<body =="" ```="" alink="```" bgcolor="```" color_al_1="" color_bg_1="" color_nl_1="" color_vl_1="" link="```" vlink="```"&gt;
16&lt;font color="```
17= C_WD_CONTENT_4 
18```"&gt;   
19Only upload &lt;b&gt;*.jpg&lt;/b&gt; or &lt;b&gt;*.gif&lt;/b&gt; file!   
20&lt;br/&gt;   
21Otherwise, image may not show correctly!   
22&lt;/font&gt;
23&lt;center&gt;
24&lt;table&gt;   

If ( Len(Session("strImage")) > 0 ) Then

 1&lt;tr&gt;
 2&lt;td&gt;
 3&lt;table ```="" border="1" bordercolor="```
 4= C_WD_T_BORDER 
 5```" cellpadding="0" cellspacing="0">
 6<tr>
 7<td>```
 8= Session("strImage") 
 9```</td>
10</tr>
11</table>
12</td>
13</tr>   

Else

 1<tr>
 2<td>
 3<table border="1" bordercolor="```
 4= C_WD_T_BORDER 
 5```" cellpadding="0" cellspacing="0">
 6<tr>
 7<td align="center" valign="top">
 8<table ```="" border="0" cellpadding="0" cellspacing="0"&gt;
 9&lt;tr&gt;
10&lt;td colspan="2"&gt;&lt;font class="e-foot" color="```
11= C_WD_CONTENT_4 
12```"&gt;&lt;b&gt;Upload / preview image:&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
13&lt;/tr&gt;
14&lt;tr&gt;
15&lt;td colspan="2"&gt; &lt;/td&gt;
16&lt;/tr&gt;
17&lt;tr&gt;
18&lt;td nowrap="" valign="top"&gt;&lt;font class="e-foot" color="```
19= C_WD_CONTENT_4 
20```"&gt;&lt;b&gt;Step 1:&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
21&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
22= C_WD_CONTENT_4 
23```"&gt;Prepare an image with 72 dpi resolution.&lt;/font&gt;&lt;/td&gt;
24&lt;/tr&gt;
25&lt;tr&gt;
26&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
27= C_WD_CONTENT_4 
28```"&gt;&lt;b&gt;Step 2:&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
29&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
30= C_WD_CONTENT_4 
31```"&gt;Select your image file&lt;/font&gt;&lt;/td&gt;
32&lt;/tr&gt;
33&lt;tr&gt;
34&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
35= C_WD_CONTENT_4 
36```"&gt;&lt;b&gt;Step 3:&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
37&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
38= C_WD_CONTENT_4 
39```"&gt;Press "Upload" button&lt;/font&gt;&lt;/td&gt;
40&lt;/tr&gt;
41&lt;tr&gt;
42&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
43= C_WD_CONTENT_4 
44```"&gt;&lt;b&gt;Step 4:&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
45&lt;td valign="top"&gt;&lt;font class="e-foot" color="```
46= C_WD_CONTENT_4 
47```"&gt;Continue &lt;b&gt;OR&lt;/b&gt; repeat &lt;b&gt;Step 1-3&lt;/b&gt; to change the image&lt;/font&gt;&lt;/td&gt;
48&lt;/tr&gt;
49&lt;/table&gt;
50&lt;/td&gt;
51&lt;/tr&gt;
52&lt;/table&gt;
53&lt;/td&gt;
54&lt;/tr&gt;   

End If

 1&lt;/table&gt;
 2&lt;/center&gt;
 3&lt;form action="handle_upload.asp" enctype="multipart/form-data" id="form1" method="POST" name="form1" onsubmit="return UpLoad(this)"&gt;
 4&lt;input name="saveURL" type="hidden" value="```
 5= WEB_TEMP_PATH 
 6```"/&gt;
 7&lt;input ```"="" name="goURL" path_info")="" type="hidden" value="```
 8= Request.ServerVariables("/&gt;
 9&lt;input class="btn" name="my_file" type="file"/&gt;
10&lt;input class="btn" name="submit" type="submit" value="Upload"/&gt;
11&lt;/form&gt;
12&lt;form action="```
13= thisFile 
14```" id="form2" name="form2"&gt;
15&lt;input class="btn" name="imageCancel" type="submit" value="Press Here To Cancel Image!"/&gt;
16&lt;br/&gt; &lt;br/&gt;
17&lt;input class="btn" id="submit1" name="submit1" onclick="window.opener.focus();window.close();" type="submit" value="Finish!"/&gt;
18&lt;/form&gt;
19&lt;/body&gt;
20&lt;/head&gt;&lt;/html&gt;
Published At
Categories with Web编程
Tagged with
comments powered by Disqus