Randomly generated filename.

Discussion in 'ASP General' started by J1C, Oct 19, 2005.

  1. J1C

    J1C Guest

    How could I create a random filename for a single-use download? So, if
    a user was to download a file from a site it would send them a unique
    filename that could only be used once. That link would not be available
    after the download completed.
    J1C, Oct 19, 2005
    #1
    1. Advertising

  2. J1C

    CJM Guest

    "J1C" <> wrote in message
    news:...
    > How could I create a random filename for a single-use download? So, if
    > a user was to download a file from a site it would send them a unique
    > filename that could only be used once. That link would not be available
    > after the download completed.
    >


    There are plenty of pseudo-random name generators out there. If you
    absolutely MUST provide a globally unique name then either record each name
    given and check for duplicates or simply use a GUID as a filename.
    CJM, Oct 19, 2005
    #2
    1. Advertising

  3. J1C

    ljb Guest

    "J1C" <> wrote in message
    news:...
    > How could I create a random filename for a single-use download? So, if
    > a user was to download a file from a site it would send them a unique
    > filename that could only be used once. That link would not be available
    > after the download completed.
    >


    I think the following generates unique names. It might work for you.

    MyFile = CreateObject("Scripting.FileSystemObject").GetTempName
    ljb, Oct 19, 2005
    #3
  4. J1C

    McKirahan Guest

    "J1C" <> wrote in message
    news:...
    > How could I create a random filename for a single-use download? So, if
    > a user was to download a file from a site it would send them a unique
    > filename that could only be used once. That link would not be available
    > after the download completed.
    >


    Will this help? Watch for word-wrap.

    This copies the file to be downloaded (once) to a unique, temporary
    filename then displays a link to it which, when clicked, downloads
    the file and deletes the temporary filename.

    <%@ Language="VBScript" %>
    <% Option Explicit
    '*
    Const cASP = "TempFile.asp"
    Const cTMP = "TempFile.zip"
    '*
    Dim strGTN
    Dim strRQS
    strRQS = Request.QueryString()
    Dim strRSV
    strRSV = Request.ServerVariables("HTTP_HOST")
    '*
    Dim objFSO
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    If strRQS = "" Then
    strGTN = objFSO.GetTempName()
    objFSO.CopyFile Server.MapPath(cTMP), Server.MapPath(strGTN)
    Else
    If strRSV <> "localhost" Then
    Server.Execute strRQS
    End If
    objFSO.DeleteFile Server.MapPath(strRQS)
    Response.End
    End If
    Set objFSO = Nothing
    %>
    <html>
    <head>
    <title><%=cASP%></title>
    </head>
    <body>
    Click to download: <a href="<%=cASP%>?<%=strGTN%>"><%=strGTN%></a>
    </body>
    </html>
    McKirahan, Oct 19, 2005
    #4
  5. J1C

    McKirahan Guest

    "McKirahan" <> wrote in message
    news:...
    > "J1C" <> wrote in message
    > news:...
    > > How could I create a random filename for a single-use download? So, if
    > > a user was to download a file from a site it would send them a unique
    > > filename that could only be used once. That link would not be available
    > > after the download completed.
    > >


    [snip]

    > Const cTMP = "TempFile.zip"


    Unfortunately, depending on the file extension,
    this may bring up the Download dialog.

    If the file extension is ".txt" or ".pdf" it opens the file.
    McKirahan, Oct 19, 2005
    #5
  6. J1C

    Terren Guest

    Why don't you just use the current date prefix by some random letters.
    e.g
    abc-yyyy-mm-dd-mm-ss-millisecond.fileExtension. This would almost
    certainly guarantee uniquiness unless you had a million people
    downloading the file at the exact same time with the exact same
    regional settings.
    Terren, Oct 20, 2005
    #6
  7. J1C

    Evertjan. Guest

    Terren wrote on 20 okt 2005 in microsoft.public.inetserver.asp.general:

    > Why don't you just use the current date prefix by some random letters.
    > e.g
    > abc-yyyy-mm-dd-mm-ss-millisecond.fileExtension. This would almost
    > certainly guarantee uniquiness unless you had a million people
    > downloading the file at the exact same time with the exact same
    > regional settings.
    >


    The easiest uniqueness is just a counter number, though it is not random.

    Use a database to get the autonumbered next record and delete the record
    after use or timeout.

    I bet you will just have 5 or 10 records active.

    file = "myTempfile" & mdata("autoID") & ".ext"

    You could even store the ip-number of the request as extra measure.


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
    Evertjan., Oct 20, 2005
    #7
  8. J1C

    J1C Guest

    That's exactly what I was looking for! Thanks!
    J1C, Oct 20, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    Extract filename from a filename typed by user

    =?Utf-8?B?Sm9l?=, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,019
    Travis Murray
    Aug 24, 2004
  2. jimgardener
    Replies:
    1
    Views:
    687
    Arne Vajhøj
    Dec 5, 2008
  3. Stuart

    Randomly Generated Strings

    Stuart, Feb 18, 2004, in forum: ASP General
    Replies:
    2
    Views:
    95
    Stuart
    Feb 19, 2004
  4. Replies:
    3
    Views:
    147
    Evertjan.
    Jan 15, 2007
  5. Replies:
    4
    Views:
    194
    Brian Candler
    Oct 21, 2009
Loading...

Share This Page