Replies Back to Article
How to create unique file name using PureASPupload
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
Please contact me (waldo@udzone.com) when you would like to do that. I would appreciate it.
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?
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
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?
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
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?
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