当前位置:编程学习 > asp >>

不用组件实现上载功能(英文NT)2.

答案:'---- 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 %>

上一个:TO:张日,在ASP文件中让客户端下载文本文件!
下一个:Windows 200下安装Chinaasp Fileup组件

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,