从ASP Classic上传后,PDF为空白

时间:2017-04-07 08:52:08

标签: pdf asp-classic

我正在为我必须使用ASP Classic的页面制作一个上传器,并找到了Jacob" Beezle" Gilley的上传器,它正在工作,只要它是一个txt文件。但问题发生在它是pdf文件或图像时,我需要上传它们。

问题是示例pdf文件上传到了它的位置,但它是空白的。我编辑了一些原始代码,因为我需要UTF-8编码。否则它是相同的,我将上传编辑过的代码。

    Public Sub SaveToDisk(sPath)
    Dim oFS, oFile
    Dim oStream

    If sPath = "" Or FileName = "" Then Exit Sub
    If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    If Not oFS.FolderExists(sPath) Then Exit Sub

    Set oStream = CreateObject("ADODB.Stream")
    With oStream
    .Type = 2
    .Charset = "UTF-8"
    .Mode = 3
    .Open
    .WriteText RSBinaryToString(FileData)
    .SaveToFile sPath & FileName
    .Close
    End With
    Set oStream = Nothing
End Sub

我该如何修复它,还是可以修复它? RSBinaryToString方法归功于Antonin Foller,http://www.motobit.com,我发现它有助于转换为UTF-8。 Whitout,我甚至无法打开文件。

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。

    Public Sub SaveToDisk(sPath)
    Dim oFS, oFile
    Dim oStream
    Dim strText

    If sPath = "" Or FileName = "" Then Exit Sub
    If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

    Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    If Not oFS.FolderExists(sPath) Then Exit Sub

    Set oStream = CreateObject("ADODB.Stream")
    With oStream
    .Type = 2
    .Charset = "Windows-1252"
    .Mode = 3
    .Open
    .Position = 0
    .SetEOS
    .WriteText RSBinaryToString(FileData), 0
    .SaveToFile sPath & FileName, 2
    .Close
    End With
    Set oStream = Nothing
End Sub

不使用Charset = UTF-8,而是使用Windows-1252。像魅力一样。

相关问题