Randomly generated filename.

J

J1C

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.
 
C

CJM

J1C said:
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.
 
L

ljb

J1C said:
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
 
M

McKirahan

J1C said:
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>
 
M

McKirahan

McKirahan said:
J1C said:
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.
 
T

Terren

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.
 
E

Evertjan.

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top