FileCloud 的原理简述&自己搭建文件云

FileCloud 的原理简述&自己搭建文件云

copyright(c) by zcy

关于如何使用IIS创建asp服务,请读者自行研究

代码的存储:

  • 根目录

    • filecloudEV.html 提前验证
    • filecloudEV.aspx 判断密码是否正确
    • filecloudMAIN.aspx 主界面
    • UpLoad.asp 上传界面
    • SaveFile.asp 保存文件
    • InputFilename.aspx 让用户输入文件名
    • AddPath.aspx 将当前文件加入文件清单
    • clsField.asp 文件上传的底层支持代码
    • clsUpload.asp 文件上传的底层支持代码
    • DownLoad.aspx 下载界面
    • list.txt 用户上传的文件的清单
    • files 用户上传的文件的储存文件夹

用户首先是进入filecloudEV.html进行验证:

<html>
    <head>
        <title>filecloud early verification</title>
        <meta charset="UTF-8"></meta>
    </head>
    <body>
        <form action="filecloudEV.aspx" method="post">
            <center>
                <p style="font-size:50px;">Password</p>
                <input type="password" name="password" style="font-size:50px;"></input>
                <input type="submit" value="Submit" style="font-size:50px;"></input>
            </center>
        </form>
    </body>
</html> 

一个文本框,将用户输入的密码传到filecloudEV.aspx里面去

filecloudEV.aspx

<html>
    <head>
        <title>filecloud early verification</title>
        <meta charset="UTF-8"></meta>
    </head>
    <body>
        <%
            dim a
            a=Request.Form("password")
            response.write("<center><p style=""font-size:30px"">")
            if a="XXXXXXX" then ‘验证密码是否正确
                response.write("Password is right!")%>
        <form action="filecloudMAIN.aspx" method="post"><!--只有正确才显示这个跳转按钮-->
            <input type="submit" value="跳转" style="font-size:30px"></input>
        </form>
        <%
            else
                response.write("Password is wrong!")
                response.write("Please go back")
            end if
            response.write("</p></center>")
        %>
    </body>
</html>

然后进入主界面:

filecloudMAIN.aspx

<html>
    <head>
        <title>FilecloudMAIN</title>
        <meta charset="UTF-8"></meta>
    </head>
    <body>
        <center>
            <a href="./UpLoad.asp" style="font-size:50px">UpLoad</a><br /><br />
            <a href="./DownLoad.aspx" style="font-size:50px">DownLoad</a><br /><br />
        </center>
    </body>
</html>

其实就只是显示了两个超链接:

先来介绍一下上传:

UpLoad.asp

<html>
    <head>
        <title>UpLoad</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <form method="post" encType="multipart/form-data" action="SaveFile.asp">
            <input type="File" name="File1">
            <input type="Submit" value="Upload">
        </form>
    </body>
</html>

把文件流传到SaveFile.asp中

SaveFile.asp

<!--#INCLUDE FILE="clsUpload.asp"--> <!--引用clsUpLoad.asp-->
<html>
    <head>
        <title>SaveFile</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <%
            Dim Upload
            Dim Folder
            Set Upload = New clsUpload
            Folder = Server.MapPath("Uploads") & "\" ‘绑定储存文件的路径
            Upload("File1").SaveAs Folder & Upload("File1").FileName ‘保存文件
            Set Upload = Nothing
            Response.Write("<script>alert(‘UpLoad Success!‘);window.location.href=‘InputFilename.aspx‘</script>") ‘跳转到InputFilename.aspx
        %>
    </body>
</html>

接下来介绍一下clsUpload.asp

声明:这个文件以及下面的clsField.asp都是我从Stack Overflow中找到的

clsUpload.asp

<!--METADATA
  TYPE="TypeLib"
  NAME="Microsoft ActiveX Data Objects 2.5 Library"
  UUID="{00000205-0000-0010-8000-00AA006D2EA4}"
  VERSION="2.5"
-->
<!--#INCLUDE FILE="clsField.asp"-->
?
<%
‘ ------------------------------------------------------------------------------
‘   Author:     Lewis Moten
‘   Date:       March 19, 2002
‘ ------------------------------------------------------------------------------
?
‘ Upload class retrieves multi-part form data posted to web page
‘ and parses it into objects that are easy to interface with.
‘ Requires MDAC (ADODB) COM components found on most servers today
‘ Additional compenents are not necessary.
‘
?
Class clsUpload
‘ ------------------------------------------------------------------------------
?
    Private mbinData            ‘ bytes visitor sent to server
    Private mlngChunkIndex      ‘ byte where next chunk starts
    Private mlngBytesReceived   ‘ length of data
    Private mstrDelimiter       ‘ Delimiter between multipart/form-data (43 chars)
?
    Private CR                  ‘ ANSI Carriage Return
    Private LF                  ‘ ANSI Line Feed
    Private CRLF                ‘ ANSI Carriage Return & Line Feed
?
    Private mobjFieldAry()      ‘ Array to hold field objects
    Private mlngCount           ‘ Number of fields parsed
?
‘ ------------------------------------------------------------------------------
    Private Sub RequestData
?
        Dim llngLength      ‘ Number of bytes received
?
        ‘ Determine number bytes visitor sent
        mlngBytesReceived = Request.TotalBytes
?
        ‘ Store bytes recieved from visitor
        mbinData = Request.BinaryRead(mlngBytesReceived)
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Sub ParseDelimiter()
?
        ‘ Delimiter seperates multiple pieces of form data
            ‘ "around" 43 characters in length
            ‘ next character afterwards is carriage return (except last line has two --)
            ‘ first part of delmiter is dashes followed by hex number
            ‘ hex number is possibly the browsers session id?
?
        ‘ Examples:
?
        ‘ -----------------------------7d230d1f940246
        ‘ -----------------------------7d22ee291ae0114
?
        mstrDelimiter = MidB(mbinData, 1, InStrB(1, mbinData, CRLF) - 1)
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Sub ParseData()
?
        ‘ This procedure loops through each section (chunk) found within the
        ‘ delimiters and sends them to the parse chunk routine
?
        Dim llngStart   ‘ start position of chunk data
        Dim llngLength  ‘ Length of chunk
        Dim llngEnd     ‘ Last position of chunk data
        Dim lbinChunk   ‘ Binary contents of chunk
?
        ‘ Initialize at first character
        llngStart = 1
?
        ‘ Find start position
        llngStart = InStrB(llngStart, mbinData, mstrDelimiter & CRLF)
?
        ‘ While the start posotion was found
        While Not llngStart = 0
?
            ‘ Find the end position (after the start position)
            llngEnd = InStrB(llngStart + 1, mbinData, mstrDelimiter) - 2
?
            ‘ Determine Length of chunk
            llngLength = llngEnd - llngStart
?
            ‘ Pull out the chunk
            lbinChunk = MidB(mbinData, llngStart, llngLength)
?
            ‘ Parse the chunk
            Call ParseChunk(lbinChunk)
?
            ‘ Look for next chunk after the start position
            llngStart = InStrB(llngStart + 1, mbinData, mstrDelimiter & CRLF)
?
        Wend
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Sub ParseChunk(ByRef pbinChunk)
?
        ‘ This procedure gets a chunk passed to it and parses its contents.
        ‘ There is a general format that the chunk follows.
?
        ‘ First, the deliminator appears
?
        ‘ Next, headers are listed on each line that define properties of the chunk.
?
        ‘   Content-Disposition: form-data: name="File1"; filename="C:\Photo.gif"
        ‘   Content-Type: image/gif
?
        ‘ After this, a blank line appears and is followed by the binary data.
?
        Dim lstrName            ‘ Name of field
        Dim lstrFileName        ‘ File name of binary data
        Dim lstrContentType     ‘ Content type of binary data
        Dim lbinData            ‘ Binary data
        Dim lstrDisposition     ‘ Content Disposition
        Dim lstrValue           ‘ Value of field
?
        ‘ Parse out the content dispostion
        lstrDisposition = ParseDisposition(pbinChunk)
?
            ‘ And Parse the Name
            lstrName = ParseName(lstrDisposition)
?
            ‘ And the file name
            lstrFileName = ParseFileName(lstrDisposition)
?
        ‘ Parse out the Content Type
        lstrContentType = ParseContentType(pbinChunk)
?
        ‘ If the content type is not defined, then assume the
        ‘ field is a normal form field
        If lstrContentType = "" Then
?
            ‘ Parse Binary Data as Unicode
            lstrValue = CStrU(ParseBinaryData(pbinChunk))
?
        ‘ Else assume the field is binary data
        Else
?
            ‘ Parse Binary Data
            lbinData = ParseBinaryData(pbinChunk)
?
        End If
?
        ‘ Add a new field
        Call AddField(lstrName, lstrFileName, lstrContentType, lstrValue, lbinData)
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Sub AddField(ByRef pstrName, ByRef pstrFileName, ByRef pstrContentType, ByRef pstrValue, ByRef pbinData)
?
        Dim lobjField       ‘ Field object class
?
        ‘ Add a new index to the field array
        ‘ Make certain not to destroy current fields
        ReDim Preserve mobjFieldAry(mlngCount)
?
        ‘ Create new field object
        Set lobjField = New clsField
?
        ‘ Set field properties
        lobjField.Name = pstrName
        lobjField.FilePath = pstrFileName
        lobjField.FileName = Mid(pstrFileName, InStrRev(pstrFileName, "\") + 1) ‘ <= line added to set the file name
        lobjField.ContentType = pstrContentType
?
        ‘ If field is not a binary file
        If LenB(pbinData) = 0 Then
?
            lobjField.BinaryData = ChrB(0)
            lobjField.Value = pstrValue
            lobjField.Length = Len(pstrValue)
?
        ‘ Else field is a binary file
        Else
?
            lobjField.BinaryData = pbinData
            lobjField.Length = LenB(pbinData)
            lobjField.Value = ""
?
        End If
?
        ‘ Set field array index to new field
        Set mobjFieldAry(mlngCount) = lobjField
?
        ‘ Incriment field count
        mlngCount = mlngCount + 1
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Function ParseBinaryData(ByRef pbinChunk)
?
        ‘ Parses binary content of the chunk
?
        Dim llngStart   ‘ Start Position
?
        ‘ Find first occurence of a blank line
        llngStart = InStrB(1, pbinChunk, CRLF & CRLF)
?
        ‘ If it doesn‘t exist, then return nothing
        If llngStart = 0 Then Exit Function
?
        ‘ Incriment start to pass carriage returns and line feeds
        llngStart = llngStart + 4
?
        ‘ Return the last part of the chunk after the start position
        ParseBinaryData = MidB(pbinChunk, llngStart)
?
    End Function
‘ ------------------------------------------------------------------------------
    Private Function ParseContentType(ByRef pbinChunk)
?
        ‘ Parses the content type of a binary file.
        ‘   example: image/gif is the content type of a GIF image.
?
        Dim llngStart   ‘ Start Position
        Dim llngEnd     ‘ End Position
        Dim llngLength  ‘ Length
?
        ‘ Fid the first occurance of a line starting with Content-Type:
        llngStart = InStrB(1, pbinChunk, CRLF & CStrB("Content-Type:"), vbTextCompare)
?
        ‘ If not found, return nothing
        If llngStart = 0 Then Exit Function
?
        ‘ Find the end of the line
        llngEnd = InStrB(llngStart + 15, pbinChunk, CR)
?
        ‘ If not found, return nothing
        If llngEnd = 0 Then Exit Function
?
        ‘ Adjust start position to start after the text "Content-Type:"
        llngStart = llngStart + 15
?
        ‘ If the start position is the same or past the end, return nothing
        If llngStart >= llngEnd Then Exit Function
?
        ‘ Determine length
        llngLength = llngEnd - llngStart
?
        ‘ Pull out content type
        ‘ Convert to unicode
        ‘ Trim out whitespace
        ‘ Return results
        ParseContentType = Trim(CStrU(MidB(pbinChunk, llngStart, llngLength)))
?
    End Function
‘ ------------------------------------------------------------------------------
    Private Function ParseDisposition(ByRef pbinChunk)
?
        ‘ Parses the content-disposition from a chunk of data
        ‘
        ‘ Example:
        ‘
        ‘   Content-Disposition: form-data: name="File1"; filename="C:\Photo.gif"
        ‘
        ‘   Would Return:
        ‘       form-data: name="File1"; filename="C:\Photo.gif"
?
        Dim llngStart   ‘ Start Position
        Dim llngEnd     ‘ End Position
        Dim llngLength  ‘ Length
?
        ‘ Find first occurance of a line starting with Content-Disposition:
        llngStart = InStrB(1, pbinChunk, CRLF & CStrB("Content-Disposition:"), vbTextCompare)
?
        ‘ If not found, return nothing
        If llngStart = 0 Then Exit Function
?
        ‘ Find the end of the line
        llngEnd = InStrB(llngStart + 22, pbinChunk, CRLF)
?
        ‘ If not found, return nothing
        If llngEnd = 0 Then Exit Function
?
        ‘ Adjust start position to start after the text "Content-Disposition:"
        llngStart = llngStart + 22
?
        ‘ If the start position is the same or past the end, return nothing
        If llngStart >= llngEnd Then Exit Function
?
        ‘ Determine Length
        llngLength = llngEnd - llngStart
?
        ‘ Pull out content disposition
        ‘ Convert to Unicode
        ‘ Return Results
        ParseDisposition = CStrU(MidB(pbinChunk, llngStart, llngLength))
?
    End Function
‘ ------------------------------------------------------------------------------
    Private Function ParseName(ByRef pstrDisposition)
?
        ‘ Parses the name of the field from the content disposition
        ‘
        ‘ Example
        ‘
        ‘   form-data: name="File1"; filename="C:\Photo.gif"
        ‘
        ‘   Would Return:
        ‘       File1
?
        Dim llngStart   ‘ Start Position
        Dim llngEnd     ‘ End Position
        Dim llngLength  ‘ Length
?
        ‘ Find first occurance of text name="
        llngStart = InStr(1, pstrDisposition, "name=""", vbTextCompare)
?
        ‘ If not found, return nothing
        If llngStart = 0 Then Exit Function
?
        ‘ Find the closing quote
        llngEnd = InStr(llngStart + 6, pstrDisposition, """")
?
        ‘ If not found, return nothing
        If llngEnd = 0 Then Exit Function
?
        ‘ Adjust start position to start after the text name="
        llngStart = llngStart + 6
?
        ‘ If the start position is the same or past the end, return nothing
        If llngStart >= llngEnd Then Exit Function
?
        ‘ Determine Length
        llngLength = llngEnd - llngStart
?
        ‘ Pull out field name
        ‘ Return results
        ParseName = Mid(pstrDisposition, llngStart, llngLength)
?
    End Function
‘ ------------------------------------------------------------------------------
    Private Function ParseFileName(ByRef pstrDisposition)
        ‘ Parses the name of the field from the content disposition
        ‘
        ‘ Example
        ‘
        ‘   form-data: name="File1"; filename="C:\Photo.gif"
        ‘
        ‘   Would Return:
        ‘       C:\Photo.gif
?
        Dim llngStart   ‘ Start Position
        Dim llngEnd     ‘ End Position
        Dim llngLength  ‘ Length
?
        ‘ Find first occurance of text filename="
        llngStart = InStr(1, pstrDisposition, "filename=""", vbTextCompare)
?
        ‘ If not found, return nothing
        If llngStart = 0 Then Exit Function
?
        ‘ Find the closing quote
        llngEnd = InStr(llngStart + 10, pstrDisposition, """")
?
        ‘ If not found, return nothing
        If llngEnd = 0 Then Exit Function
?
        ‘ Adjust start position to start after the text filename="
        llngStart = llngStart + 10
?
        ‘ If the start position is the same of past the end, return nothing
        If llngStart >= llngEnd Then Exit Function
?
        ‘ Determine length
        llngLength = llngEnd - llngStart
?
        ‘ Pull out file name
        ‘ Return results
        ParseFileName = Mid(pstrDisposition, llngStart, llngLength)
?
    End Function
‘ ------------------------------------------------------------------------------
    Public Property Get Count()
?
        ‘ Return number of fields found
        Count = mlngCount
?
    End Property
‘ ------------------------------------------------------------------------------
?
    Public Default Property Get Fields(ByVal pstrName)
?
        Dim llngIndex   ‘ Index of current field
?
        ‘ If a number was passed
        If IsNumeric(pstrName) Then
?
            llngIndex = CLng(pstrName)
?
            ‘ If programmer requested an invalid number
            If llngIndex > mlngCount - 1 Or llngIndex < 0 Then
                ‘ Raise an error
                Call Err.Raise(vbObjectError + 1, "clsUpload.asp", "Object does not exist within the ordinal reference.")
                Exit Property
            End If
?
            ‘ Return the field class for the index specified
            Set Fields = mobjFieldAry(pstrName)
?
        ‘ Else a field name was passed
        Else
?
            ‘ convert name to lowercase
            pstrName = LCase(pstrname)
?
            ‘ Loop through each field
            For llngIndex = 0 To mlngCount - 1
?
                ‘ If name matches current fields name in lowercase
                If LCase(mobjFieldAry(llngIndex).Name) = pstrName Then
?
                    ‘ Return Field Class
                    Set Fields = mobjFieldAry(llngIndex)
                    Exit Property
?
                End If
?
            Next
?
        End If
?
        ‘ If matches were not found, return an empty field
        Set Fields = New clsField
?
‘       ‘ ERROR ON NonExistant:
‘       ‘ If matches were not found, raise an error of a non-existent field
‘       Call Err.Raise(vbObjectError + 1, "clsUpload.asp", "Object does not exist within the ordinal reference.")
‘       Exit Property
?
    End Property
‘ ------------------------------------------------------------------------------
    Private Sub Class_Terminate()
?
        ‘ This event is called when you destroy the class.
        ‘
        ‘ Example:
        ‘   Set objUpload = Nothing
        ‘
        ‘ Example:
        ‘   Response.End
        ‘
        ‘ Example:
        ‘   Page finnishes executing ...
?
        Dim llngIndex   ‘ Current Field Index
?
        ‘ Loop through fields
        For llngIndex = 0 To mlngCount - 1
?
            ‘ Release field object
            Set mobjFieldAry(llngIndex) = Nothing
?
        Next
?
        ‘ Redimension array and remove all data within
        ReDim mobjFieldAry(-1)
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Sub Class_Initialize()
?
        ‘ This event is called when you instantiate the class.
        ‘
        ‘ Example:
        ‘   Set objUpload = New clsUpload
?
        ‘ Redimension array with nothing
        ReDim mobjFieldAry(-1)
?
        ‘ Compile ANSI equivilants of carriage returns and line feeds
?
        CR = ChrB(Asc(vbCr))    ‘ vbCr      Carriage Return
        LF = ChrB(Asc(vbLf))    ‘ vbLf      Line Feed
        CRLF = CR & LF          ‘ vbCrLf    Carriage Return & Line Feed
?
        ‘ Set field count to zero
        mlngCount = 0
?
        ‘ Request data
        Call RequestData
?
        ‘ Parse out the delimiter
        Call ParseDelimiter()
?
        ‘ Parse the data
        Call ParseData
?
    End Sub
‘ ------------------------------------------------------------------------------
    Private Function CStrU(ByRef pstrANSI)
?
        ‘ Converts an ANSI string to Unicode
        ‘ Best used for small strings
?
        Dim llngLength  ‘ Length of ANSI string
        Dim llngIndex   ‘ Current position
?
        ‘ determine length
        llngLength = LenB(pstrANSI)
?
        ‘ Loop through each character
        For llngIndex = 1 To llngLength
?
            ‘ Pull out ANSI character
            ‘ Get Ascii value of ANSI character
            ‘ Get Unicode Character from Ascii
            ‘ Append character to results
            CStrU = CStrU & Chr(AscB(MidB(pstrANSI, llngIndex, 1)))
?
        Next
?
    End Function
‘ ------------------------------------------------------------------------------
    Private Function CStrB(ByRef pstrUnicode)
?
        ‘ Converts a Unicode string to ANSI
        ‘ Best used for small strings
?
        Dim llngLength  ‘ Length of ANSI string
        Dim llngIndex   ‘ Current position
?
        ‘ determine length
        llngLength = Len(pstrUnicode)
?
        ‘ Loop through each character
        For llngIndex = 1 To llngLength
?
            ‘ Pull out Unicode character
            ‘ Get Ascii value of Unicode character
            ‘ Get ANSI Character from Ascii
            ‘ Append character to results
            CStrB = CStrB & ChrB(Asc(Mid(pstrUnicode, llngIndex, 1)))
?
        Next
?
    End Function
‘ ------------------------------------------------------------------------------
End Class
‘ ------------------------------------------------------------------------------
%>

clsField.asp

<%
‘ ------------------------------------------------------------------------------
‘   Author:     Lewis Moten
‘   Date:       March 19, 2002
‘ ------------------------------------------------------------------------------
?
‘ Field class represents interface to data passed within one field
‘
‘ ------------------------------------------------------------------------------
Class clsField
?
    Public Name             ‘ Name of the field defined in form
?
    Private mstrPath        ‘ Full path to file on visitors computer
                            ‘ C:\Documents and Settings\lmoten\Desktop\Photo.gif
?
    Public FileDir          ‘ Directory that file existed in on visitors computer
                            ‘ C:\Documents and Settings\lmoten\Desktop
?
    Public FileExt          ‘ Extension of the file
                            ‘ GIF
?
    Public FileName         ‘ Name of the file
                            ‘ Photo.gif
?
    Public ContentType      ‘ Content / Mime type of file
                            ‘ image/gif
?
    Public Value            ‘ Unicode value of field (used for normail form fields - not files)
?
    Public BinaryData       ‘ Binary data passed with field (for files)
?
    Public Length           ‘ byte size of value or binary data
?
    Private mstrText        ‘ Text buffer
                                ‘ If text format of binary data is requested more then
                                ‘ once, this value will be read to prevent extra processing
?
‘ ------------------------------------------------------------------------------
    Public Property Get BLOB()
        BLOB = BinaryData
    End Property
‘ ------------------------------------------------------------------------------
    Public Function BinaryAsText()
?
        ‘ Binary As Text returns the unicode equivilant of the binary data.
        ‘ this is useful if you expect a visitor to upload a text file that
        ‘ you will need to work with.
?
        ‘ NOTICE:
        ‘ NULL values will prematurely terminate your Unicode string.
        ‘ NULLs are usually found within binary files more often then plain-text files.
        ‘ a simple way around this may consist of replacing null values with another character
        ‘ such as a space " "
?
        Dim lbinBytes
        Dim lobjRs
?
        ‘ Don‘t convert binary data that does not exist
        If Length = 0 Then Exit Function
        If LenB(BinaryData) = 0 Then Exit Function
?
        ‘ If we previously converted binary to text, return the buffered content
        If Not Len(mstrText) = 0 Then
            BinaryAsText = mstrText
            Exit Function
        End If
?
        ‘ Convert Integer Subtype Array to Byte Subtype Array
        lbinBytes = ASCII2Bytes(BinaryData)
?
        ‘ Convert Byte Subtype Array to Unicode String
        mstrText = Bytes2Unicode(lbinBytes)
?
        ‘ Return Unicode Text
        BinaryAsText = mstrText
?
    End Function
‘ ------------------------------------------------------------------------------
    Public Sub SaveAs(ByRef pstrFileName)
?
        Dim lobjStream
        Dim lobjRs
        Dim lbinBytes
?
        ‘ Don‘t save files that do not posess binary data
        If Length = 0 Then Exit Sub
        If LenB(BinaryData) = 0 Then Exit Sub
?
        ‘ Create magical objects from never never land
        Set lobjStream = Server.CreateObject("ADODB.Stream")
?
        ‘ Let stream know we are working with binary data
        lobjStream.Type = adTypeBinary
?
        ‘ Open stream
        Call lobjStream.Open()
?
        ‘ Convert Integer Subtype Array to Byte Subtype Array
        lbinBytes = ASCII2Bytes(BinaryData)
?
        ‘ Write binary data to stream
        Call lobjStream.Write(lbinBytes)
?
        ‘ Save the binary data to file system
        ‘   Overwrites file if previously exists!
        Call lobjStream.SaveToFile(pstrFileName, adSaveCreateOverWrite)
?
        ‘ Close the stream object
        Call lobjStream.Close()
?
        ‘ Release objects
        Set lobjStream = Nothing
?
    End Sub
‘ ------------------------------------------------------------------------------
    Public Property Let FilePath(ByRef pstrPath)
?
        mstrPath = pstrPath
?
        ‘ Parse File Ext
        If Not InStrRev(pstrPath, ".") = 0 Then
            FileExt = Mid(pstrPath, InStrRev(pstrPath, ".") + 1)
            FileExt = UCase(FileExt)
        End If
?
        ‘ Parse File Name
        If Not InStrRev(pstrPath, "\") = 0 Then
            FileName = Mid(pstrPath, InStrRev(pstrPath, "\") + 1)
        End If
?
        ‘ Parse File Dir
        If Not InStrRev(pstrPath, "\") = 0 Then
            FileDir = Mid(pstrPath, 1, InStrRev(pstrPath, "\") - 1)
        End If
?
    End Property
‘ ------------------------------------------------------------------------------
    Public Property Get FilePath()
        FilePath = mstrPath
    End Property
‘ ------------------------------------------------------------------------------
    Private Function ASCII2Bytes(ByRef pbinBinaryData)
?
        Dim lobjRs
        Dim llngLength
        Dim lbinBuffer
?
        ‘ get number of bytes
        llngLength = LenB(pbinBinaryData)
?
        Set lobjRs = Server.CreateObject("ADODB.Recordset")
?
        ‘ create field in an empty recordset to hold binary data
        Call lobjRs.Fields.Append("BinaryData", adLongVarBinary, llngLength)
?
        ‘ Open recordset
        Call lobjRs.Open()
?
        ‘ Add a new record to recordset
        Call lobjRs.AddNew()
?
        ‘ Populate field with binary data
        Call lobjRs.Fields("BinaryData").AppendChunk(pbinBinaryData & ChrB(0))
?
        ‘ Update / Convert Binary Data
            ‘ Although the data we have is binary - it has still been
            ‘ formatted as 4 bytes to represent each byte.  When we
            ‘ update the recordset, the Integer Subtype Array that we
            ‘ passed into the Recordset will be converted into a
            ‘ Byte Subtype Array
        Call lobjRs.Update()
?
        ‘ Request binary data and save to stream
        lbinBuffer = lobjRs.Fields("BinaryData").GetChunk(llngLength)
?
        ‘ Close recordset
        Call lobjRs.Close()
?
        ‘ Release recordset from memory
        Set lobjRs = Nothing
?
        ‘ Return Bytes
        ASCII2Bytes = lbinBuffer
?
    End Function
‘ ------------------------------------------------------------------------------
    Private Function Bytes2Unicode(ByRef pbinBytes)
?
        Dim lobjRs
        Dim llngLength
        Dim lstrBuffer
?
        llngLength = LenB(pbinBytes)
?
        Set lobjRs = Server.CreateObject("ADODB.Recordset")
?
        ‘ Create field in an empty recordset to hold binary data
        Call lobjRs.Fields.Append("BinaryData", adLongVarChar, llngLength)
?
        ‘ Open Recordset
        Call lobjRs.Open()
?
        ‘ Add a new record to recordset
        Call lobjRs.AddNew()
?
        ‘ Populate field with binary data
        Call lobjRs.Fields("BinaryData").AppendChunk(pbinBytes)
?
        ‘ Update / Convert.
            ‘ Ensure bytes are proper subtype
        Call lobjRs.Update()
?
        ‘ Request unicode value of binary data
        lstrBuffer = lobjRs.Fields("BinaryData").Value
?
        ‘ Close recordset
        Call lobjRs.Close()
?
        ‘ Release recordset from memory
        Set lobjRs = Nothing
?
        ‘ Return Unicode
        Bytes2Unicode = lstrBuffer
?
    End Function
?
‘ ------------------------------------------------------------------------------
End Class
‘ ------------------------------------------------------------------------------
%>

但是我们还需要把这个文件名加到文件列表中(如果说不添加,可以在服务器后端运行一个不断获取文件夹内的文件列表写入list.txt比较麻烦

于是我们就需要让用户自己输入刚才上传的文件名:

InputFilename.aspx

<html>
    <head>
        <title>Filename Inputer</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <form action="AddPath.aspx" method="post"><!--让AddPath.aspx将它加入列表-->
            <p>Input the file‘s filename you upload just then:</p>
            <input type="input" name="fnm">
            <input type="submit" value="Submit">
        </form>
    </body>
</html>

AddPath.aspx

<%@ Page Debug="true" %>
<html>
    <head>
        <title>AddPath</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <%
            Dim fso
            Dim f
            fso=CreateObject("Scripting.FileSystemObject")
            f=fso.OpenTextFile("D:\cloud\list.txt",8,True) ‘注意这里要用绝对路径,不然会引发权限错误
            Dim fnm
            fnm=Request.Form("fnm")
            f.WriteLine(fnm)
            f.Close
            Response.write("<script>alert(‘UpLoad Success!‘);window.location.href=‘./UpLoad.asp‘;</script>") ‘跳转回去
        %>
    </body>
</html>

上传到此结束,接下来看下载

DownLoad.aspx

<html>
    <head>
        <title>DownLoad</title>
        <meta charset="UTF-8"></meta>
    </head>
    <body>
        <%
            Dim Fso
            Dim myFile
            Fso = Server.CreateObject("Scripting.FileSystemObject")
            myFile = Fso.OpenTextFile(Server.MapPath("list.txt"),1,True)
            While Not myFile.AtEndOfStream ‘将文件列表中的全部输出
                Dim V=myFile.ReadLine
                Response.Write("<a href=‘UpLoads\" & V & "‘ download=‘" & V & "‘style=‘font-size:30px‘>" & V & "</a><br /><br />") ‘输出下载标签
            End While
        %>
    </body>
</html>

到此,所有文件都写完了,接下来可以http://localhost:端口/filecloudEV.html查看效果了

但是这个网址还有一个问题:

如果用户直接访问filecloudMAIN文件,TA可以直接绕过之前的验证,所以需要cookies的传递,请读者自行研究

原文地址:https://www.cnblogs.com/zhuchengyang/p/10160876.html

时间: 2024-07-31 02:08:11

FileCloud 的原理简述&自己搭建文件云的相关文章

docker 搭建私有云盘 Seafile

缘起 现如今各种云存储服务其实挺多的,国外有经典的DropBox.Google Drive.微软的OneDrive等,国内也有可以免费使用的各种云. 那么为什么想要搭建私有云存储呢?主要是本着"自己的数据自己管理"的原则. 其一是防止数据被窃取.这些云存储服务往往是和自己的某些平台账号绑定在一起的,或者至少是跟自己的某个邮箱绑定在一起的(密码重设),一旦平台账号或邮箱被黑客获取,所有的数据就一览无余了.再加之网络上社工库泛滥,很多人喜欢在各种网络服务上使用相同 的密码,往往是某一个账号

在ECS上搭建阿里云数据库RDS的只读实例

在ecs上搭建阿里云数据库rds的只读实例 一.搭建环境 1. 阿里云的云数据库rds版,MySQL版本:MySQL 5.6.16,做主服务器,8核16G内存. 2. Ecs服务器一台:CentOS release 6.8,安装MySQL 5.6.40,做从服务器,Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz,两核4G内存. 二.目的 通过搭建只读实例(mysql主从),实时将数据从云数据库rds,复制到ecs上的MySQL从库,减少rds读取数据的压力.

Centos7 搭建owncloud云存储

Centos7 搭建owncloud云存储 首先准备必要的软件和资料. 这里我已经整理好了: 百度云共享 不过最好还是自己去官网上下.这里只不过是提供了快捷方式. owncloud官网:https://www.owncloud.org 安装vmware 和 虚拟机的安装就不演示了.下面直接开始演示安装LAMP环境, 和 owncloud的安装. 推荐使用putty或者其他ssh软件远程连接到虚拟机再开始输入命令. 比直接再虚拟机内完成操作方便. 我这里使用xshell进行远程连接. 效果都是一样

超详细, 手把手教你搭建阿里云个人站点

# 搭建阿里云服务器 [TOC] ## 0. 费用 > 第一步先交代一下大家比较关心的东东, 以下是所有费用: * 阿里云服务器: 三年 229 元 ![f52e0b7ac813e6a7473d44e750c0e7ff.png](evernotecid://7D5162EA-5D37-473F-9C81-E2FEC23DD3B2/appyinxiangcom/18499762/ENResource/p482) * 域名: 三年: 150 元 ![4043d91cc2099623d517013ac

TCP/IP协议工作原理简述

TCP/IP协议工作原理简述 Table of Contents 1 概要 2 应用层 3 传输层 4 网络层 5 链路层 1 概要 协议是什么?协议是一组为完成特定需求或功能而定义的标准通讯格式.协议是服务于具体需求或功能的,它不能独立存在. 制定TCP/IP协议的目的是为了解决主机互联以及互联的主机上的应用通讯的问题.TCP/IP协议共有四层:应用层.传输层.网络层.链路层.应用层实际就是我们的应用程序,对于非具体应用而言这一层的协议是未定义的,需要我们自己根据我们具体的业务模型来制定.传输

[转]文件上传原理:Web上传文件的原理及实现

现在有很多Web程序都有上传功能,实现上传功能的组件或框架也很多,如基于java的CommonsFileUpload.还有Struts1.x和Struts2中带的上传文件功能(实际上,Struts2在底层也使用了CommonsFileUpload).在asp.net中也有相应的上传文件的控件. 虽然现在有很多上传组件可以利用,但是了解Web上传文件的原理,对于处理突然出现的问题会有很大的帮助,下面就来讲一下通过浏览器上传文件的基本原理.在了解了原理之后,就可以非常容易地自制满足自身需要的上传组件

java多线程模式ThreadLocal原理简述及其使用详解

原创整理不易,转载请注明出处:java多线程模式ThreadLocal原理简述及其使用详解 代码下载地址:http://www.zuidaima.com/share/1781557457128448.htm ThreadLocal是为了使每个线程保存一份属于自己的数据. 先看一个使用ThreadLocal的实例. package com.zuidaima.aop.framework; import com.zuidaima.core.NamedThreadLocal; public abstra

Volley实现原理简述

Volley实现原理简述 一.介绍 Volley是Goole退出的Android异步网络请求框架和图片加载框架. 主要特点: 1)扩展性强.Volley大多是基于接口的设计. 2)符合Http规范. 3)Android2.3及以上版本默认基于HttpUrlConnection,2.3以下基于HttpClient. 4)提供简便的图片加载工具. 二.使用 1.调用:通过newRequestQueue()函数新建并启动一个请求队列,向RequestQueuezhon 不断add Request. 代

Gexmul虚拟机内存空间原理简述

Gxemul将内存空间分为两部分管理,一部分是物理内存,地址分配到0x00000000,另一部分是device的地址,注册device的时候由device自己指定空间 1 创建物理内存 memory.cc memory_new {     初始化物理内存参数     mem->physical_max = physical_max;     mem->dev_dyntrans_alignment = 4095;     创建物理内存     mem->pagetable = (unsig