Unique File Names

Results 1 to 4 of 4

Thread: Unique File Names

  1. #1
    dataman Guest

    Default Unique File Names

    I need to assure that all files I am uploading through aspSmart upload are unique. Whether it be images, or Word Documents... I would like to either attach the id onto the file name or a random number between 1 and whatever. Any ideas on the easiest way to do this?

  2. #2
    Join Date
    Dec 1969

    Default Guaranteed...

    ...is to use the Session.SessionID *and* the date/time, probably converting the latter to the number of seconds since some start date.<BR><BR>SO:<BR><BR>&#060;%<BR>unique = "File_" & DateDiff("s",DateSerial(1970,1,1),Now()) & "_" & Session.SessionID & ".jpg"<BR>%&#062;<BR><BR>Normally, you&#039;d think you could just use Session.SessionID, but if the server gets restarted it is *possible* (admittedly, unlikely, but possible) to get a duplicate SessionID.<BR><BR>Normally, you&#039;d think the time, alone, would be good enough. But it&#039;s certainly possible to have two users post within the same second, isn&#039;t it?<BR><BR>But put the two together...and no way you&#039;ll get a duplicate.<BR><BR>

  3. #3
    dataman Guest

    Default RE: Guaranteed...

    Thank you Bill for helping me. I am having troubles implementing into my page what you showed me. I know it has to be something stupid and small that I am missing. Below is the code that is responsible for uploading the file, and uploading the name to the DB. Would you be so kind as to point me in the right direction?<BR><BR>.files("imagename").SaveAs(filer oot & "uploadfiles\" & .files("imagename").fileName)<BR><BR>imagenamevar = .files("imagename").FileName<BR><BR>Set rsAddMain = conn.execute ("INSERT INTO table(imagename) VALUES (&#039;" & imagenamevar & "&#039;)")<BR><BR><BR>Bless you for the help you have lent and bless you for any further help. :)<BR>

  4. #4
    dataman Guest

    Default RE: Never Mind, I got it

    Never mind Bill, I got it...just needed a lil elbow grease and both sides of my brain. Below is the code....first one is the oen that saves it to the computer and the second saves it to the DB.<BR><BR>.files("imagename").SaveAs(fileroot & "uploadfiles\" & "File_" & DateDiff("s",DateSerial(1970,1,1),Now()) & "_" & Session.SessionID & ".jpg")<BR><BR>imagenamevar = "File_" & DateDiff("s",DateSerial(1970,1,1),Now()) & "_" & Session.SessionID & ".jpg"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts