Replies Back to Article

How to create unique file name using PureASPupload

Combination with Server.MapPath directives
July 31, 2001 by Pablo Deeleman

May be some of you out there will try to use this useful script in combination with other ASP code that handles with the image size (ASPimage, others, etc).

Usually, these programs make use of the Server.MapPath directive to check some instances from the file, but the symbol "{" included in the unique filename generated by this code is not compatible with the Paths supported by Server.MapPath.

In this case, you just need to modify a little the original code as follows:

Add this code  somewhere near the top of your page.

<%
'generate a random string to create unique file name
randomize
SD_count = 1

DO

'get random number b/w 48 & 122 (0 - Z)
intRnd = int(75 * rnd + 48)

'limit string to 0-9, a-z, A-Z
if (intRnd < 57 OR intRnd > 65) AND (intRnd < 90 OR intRnd > 97) then
     listRnd = listRnd & chr(intRnd)
     SD_count = SD_count + 1
END IF

'make random string 15 chars gives 768,909,704,948,766,668,552,634,368 possible combinations on UNIX (case sensitive) or 221,073,919,720,733,357,899,776 combinations under Windows - should be enough :o)
LOOP UNTIL SD_count = 16

'make it a little more readable.
'All instances of "{" removed
strRandom = mid(listRnd,1,5) & "-" & mid(listRnd,6,5) & "-" & mid(listRnd,11,5) & "-"

%>

And that´s all, folks! I find this tip quite useful, and i recommend to save this code onto your projects as an external file (whenever SSI is supported) and use it extensively.

Happy coding!

Pablo

 

RE: Combination with Server.MapPath directives
July 31, 2001 by Waldo Smeets
Cool Pablo! Thank you very much. Maybe you can turn this FAQ and your post into a nice tutorial? It is more than a FAQ right now ;)
Please contact me (waldo@udzone.com) when you would like to do that. I would appreciate it.
Saving Both Unique Filename to DB and In Actual File Name
October 24, 2001 by Michael Youngblood
This is generally wonderful, but I want to save a unique file name to the database as well as modify the actual file name when it gets uploaded into my 'uploads' directory.  Using these two options, I seem to get one or the other.  I must be missing something.  THANKS!
Saving unique name to DB
January 18, 2002 by Mike Hyde

This is a great little addon, which is very useful.  Only problem is, the unique name is not being saved in my database.  The original name is being saved only.  The uploaded file itself is being named OK.

I tried both options listed.  I have been trying to pick through the code myself, and I can't see how the code changes mentioned (in red above) will actually affect what is saved in the database.  What am I missing?  Any suggestions?

I have find an error !!!!! little, very little... :-)
March 14, 2002 by Clemente Aceto

In this line:
UploadRequest.Item(GP_curKey).Item("value")
the "v" of "value" must be "V" ... so "Value" and not "value"

Elis - www.webelen.com

how do I get the file name?
March 25, 2002 by Tyrone Smith

I need to get the name of the file that is being uploaded so that I can send it as an attachment on an email?

 

Multiple upload
April 5, 2002 by M Rooda

Hi, i have a question does this work with multiple file upload because i have added the code and it only uploads the real picture name into the database and not the pics to my upload folder. if it doesn't work is there a way to make it work?

 

thanks in advance

mathijs

Upload asp.net unique file name
September 18, 2003 by Chris Aps

I used the method posted to generate a random charset and append it to the file name from a session var. However the next lines are causing errors - the UploadRequest.Item(GP_curKey).Item("value") = strRandom &  UploadRequest.Item(GP_curKey).Item("FileName")

do I sub Filename for the form text file value? even so, how do i get this command recognized on my form if its supposed to change the filename?

How to write the file name with its path into the database using PureASPupload
September 8, 2006 by mehmet cenk

I am building an estate agent website and after uploading the image files with PureASPupload I cant make them seen in the details page. I think its because; the file names are entered into the db without their file path. Is there a way to solve this problem.

Thanks