经典ASP表单停止使用FreeASPUpload.php脚本

时间:2013-09-26 15:27:25

标签: forms asp-classic

我有一个脚本可以上传图像并传递表单字段数据,由freeaspupload.php和我自己处理。出于某种原因,最近这里的脚本停止了工作。我无法再从我的两个表单字段中接收数据。

这是我的表格页。

<!--#include file="includes/open_db_conn.asp"-->
<!--#include file="includes/security_article.asp"-->
<!--#include file="includes/header.asp"-->
<% uid = CInt(Request.QueryString("uid"))

rs.Open "SELECT * FROM landingPage WHERE pageId =" & uid, con %>
<br>

<div class="content">
<% If Request.QueryString("post") = "successful" Then %>

    <p style="color:Red">Landing Page Edited Successfully.</p>
<% End If %>
<% If Request.QueryString("uid") > 0 Then %>
    <p style="color:Red"><a href="/landingpage.asp?id=<%= Request.QueryString("uid") %>" target="_blank">/landingpage.asp?id=<%= Request.QueryString("uid") %></a></p>
<% End If %>

<p class="header">Edit This Landing Page:</p><br>
<form action="landingpage_process.asp" name="landingForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="pageId" size="30" maxlength="255" value="<%= rs("pageId") %>"/>
<input type="hidden" name="action" value="edit" />
<table width="80%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="30%" align="left" valign="top"><p class="copy">Title:</p></td>
    <td width="70%" align="left" valign="top"><p class="copy"><input type="text" name="pageTitle" size="30" value="<%= rs("pageTitle") %>" /></p></td>
  </tr>
  <tr>
    <td width="30%" align="left" valign="top"><p class="copy">Banner Image:</p></td>
    <td width="70%" align="left" valign="top"><p class="copy"><input type="file" name="pageBanner" size="30" /></p>
    <img src="../images/pages/<%= rs("pageBanner") %>" alt="" style="max-height:75px;" /></td>
  </tr>
  <tr>
    <td align="left" valign="top" colspan="2"><p class="copy">Left Column:</p><p class="copy">
    <textarea id="pageLeftColumn" name="pageLeftColumn"><%= Replace(rs("pageLeftColumn"), "&amp;", "&") %></textarea>
    </p></td>
  </tr>
  <tr>
    <td align="left" valign="top" colspan="2"><p class="copy">Right Column (Leave blank for one large left column)</p><p class="copy">
    <textarea id="pageRightColumn" name="pageRightColumn"><%= Replace(rs("pageRightColumn"), "&amp;", "&") %></textarea>
    </p></td>
  </tr>
  <tr>
    <td align="center" valign="top" colspan="2"><center><input type="submit" value="Edit Page" /></center></td>
  </tr>
</table>

</form>

</div>

<!--#include file="includes/footer.asp"-->
<!--#include file="includes/close_db_conn.asp"-->

这是用于处理的页面:

<%@ Language=VBScript %>
<%
option explicit 

Response.Expires = -1

Server.ScriptTimeout = 600
' All communication must be in UTF-8, including the response back from the request
Session.CodePage  = 65001
%>
<!-- #include file="includes/freeaspupload.asp" -->
<!-- #include file="includes/ChkString.asp"-->
<!-- #include file="includes/open_db_conn.asp"-->
<%
Dim action, returnPage
action = "add"

returnPage = "landingpage_add.asp"

Dim uploadsDirVar
uploadsDirVar = "C:\inetpub\colloquy.com\images\pages"

function TestEnvironment()
    Dim fso, fileName, testFile, streamTest

    TestEnvironment = ""

    Set fso = Server.CreateObject("Scripting.FileSystemObject")

    if not fso.FolderExists(uploadsDirVar) then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."

        exit function
    end if

    fileName = uploadsDirVar & "\test.txt"

    on error resume next

    Set testFile = fso.CreateTextFile(fileName, true)

    If Err.Number<>0 then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."

        exit function
    end if

    Err.Clear

    testFile.Close

    fso.DeleteFile(fileName)

    If Err.Number<>0 then
        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."

        exit function
    end if

    Err.Clear

    Set streamTest = Server.CreateObject("ADODB.Stream")

    If Err.Number<>0 then
        TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."

        exit function
    end if

    Set streamTest = Nothing
end function

Dim test
Dim varStrings
Dim imageArray
Dim item
Dim tempArray

Dim fields
Dim values
Dim sql_add

function SaveFiles
        Dim Upload, fileName, fileSize, ks, i, fileKey

    on error resume next

        Set Upload = New FreeASPUpload

        Upload.Save(uploadsDirVar)

    ' If something fails inside the script, but the exception is handled

    If Err.Number<>0 then 'Exit function
        'Response.Write(Err.Description)
    End If

        SaveFiles = ""

        ks = Upload.UploadedFiles.keys

        if (UBound(ks) <> -1) then
            for each fileKey in Upload.UploadedFiles.keys
                    SaveFiles = SaveFiles & fileKey & "=>" & Upload.UploadedFiles(fileKey).FileName & "<|>"
            next
        end if

        action = Upload.Form("action")

    leftColumn = Upload.Form("pageLeftColumn")
    Response.Write(leftColumn)

        SaveFiles = SaveFiles & "pageTitle=>" & Upload.Form("pageTitle") & "<|>"
        SaveFiles = SaveFiles & "pageLeftColumn=>" & Upload.Form("pageLeftColumn") & "<|>"
        SaveFiles = SaveFiles & "pageRightColumn=>" & Upload.Form("pageRightColumn")

        If action = "edit" Then
            SaveFiles = SaveFiles & "<||>"
            SaveFiles = SaveFiles & Upload.Form("pageId")
        End If
end function

fields = ""
values = ""

test = TestEnvironment()

If len(test) < 1 Then
        varStrings = SaveFiles()

    Response.Write(varStrings)
    Response.End()

        If action = "add" Then
            imageArray = Split(varStrings,"<|>")

            For Each item In imageArray
                    tempArray = Split(item,"=>")
                    fields = fields & tempArray(0) & ", "
                    values = values & "'" & Server.HTMLEncode(replaceQuotes(tempArray(1))) & "', "
            Next

            fields = fields & "dateAdded"
            values = values & "'" & Now() & "'"

            on error resume next

            sql_add = "Insert Into landingPage (" & fields & ") Values (" & values & ");"

            con.Execute sql_add

            Dim rsIdentity 'a recordset to hold the identity value

            'This line of code will get us the indentity value for the row
            ' we just inserted!!
            Set rsIdentity = con.Execute("SELECT @@IDENTITY AS NewID")

            returnPage = "landingpage_add.asp?uid=" & rsIdentity("NewID")

            If err<>0 Then
                response.write("<p class=""header"">Error!</p><p class=""copy"">The record was not saved, please try again.</p><p class=""copy"">" & err.Description & "</p><p class=""copy"">" & sql_add & "</p>")
            End If
        End If

        If action = "edit" Then
            Dim Array1
            Dim Array2

            Array1 = Split(varStrings,"<||>")
            Array2 = Split(Array1(0),"<|>")

            imageArray = Split(varStrings,"<|>")

            Dim comma
            comma = ""

            For Each item In Array2
                    tempArray = Split(item,"=>")
                    fields = fields & comma & tempArray(0) & "='" & Server.HTMLEncode(replaceQuotes(tempArray(1) & "")) & "'"
                    comma = ", "
            Next

            fields = fields & " Where pageId=" & Array1(1)

            returnPage = "landingpage_edit.asp?uid=" & Array1(1)

            on error resume next

            sql_add = "Update landingPage Set " & fields & ";"
            ''Response.Write(sql_add)

            con.Execute sql_add

            If err<>0 Then
                response.write("<p class=""header"">Error!</p><p class=""copy"">The record was not saved, please try again.</p><p class=""copy"">" & err.Description & "</p><p class=""copy"">" & sql_add & "</p>")
            End If
        End If
End If
%>
<!--#include file="includes/close_db_conn.asp"-->
<%
If err=0 Then
    Response.Redirect returnPage & "&post=successful"
End If
%> 

底部的Response.Write(varStrings)告诉我:

pageTitle=>2013 COLLOQUY Awards Ceremony Video<|>pageLeftColumn=><|>pageRightColumn=><||>46

正如您所看到的,左侧或右侧列没有数据,但我确实在这些字段中有信息。

我已经尝试将我的textarea更改为输入,但这也不起作用(我希望它会因为标题字段仍然存在而发生)。

2 个答案:

答案 0 :(得分:2)

问题是您尝试使用不支持Request.Form的{​​{1}}来访问表单数据。

要访问您需要使用enctype="multipart/form-data"的二进制数据,最简单的方法是使用专为上传文件/图片而设置的预先编写的类,请参阅:http://www.codeguru.com/csharp/.net/net_asp/article.php/c19297/Pure-ASP-File-Upload.htm

例如,您可以访问文件和其他表单值,如下所示:

Request.BinaryRead(Request.TotalBytes)

答案 1 :(得分:0)

事实证明表单正在运行,但正在使用的测试文本包含一个窗口卷曲引号字符,该字符打破了包含该字符的表单元素的上传脚本。我不知道为什么这些角色被发明了......太烦人了。