• (nodebb)

    I suspect the developer responsible didn't understand how to split the extension off.

    Possible, but clearly the said developer didn't bother trying to find out either.

  • (nodebb)

    Come on, Remy, everyone knows that the more times you hash something, the more random it becomes.

  • (nodebb)

    The proper way in PHP to generate a UUID is actually by using the Random\Randomizer class. Now you just have to set a few bits to make it a RFC 4122 conform v4 UUID.

  • Qlbuttiq (unregistered)

    Why not allow S, C, or K? I can think of a pretty good number of words that couldn't accidentally show up in one of these "tokens" if those letters weren't used...

  • Deeseearr (unregistered) in reply to Qlbuttiq

    I'm sure that having a token read "FUQQ" or "QOQQ" would be perfectly safe and not offend anybody.

  • (nodebb)

    The real WTF is that PHP's uniqid function doesn't actually guarantee uniqueness... But I guess it's par for the course for PHP

  • RB (unregistered)

    "$extra is going to be the actual filename, which if it were me, I'd append the unique fields so the name remains sortable, not prepend them- "

    errr - sorry, but they "are" appending the filename....

    wtf?

  • (nodebb) in reply to MaxiTB

    Of course, UUIDs are only probabilistically "unique"... If you're very, very unlucky, you'll end up with a collision (admittedly, winning the lottery is likelier... until Finagle's Law steps in).

  • (author) in reply to RB

    Right, but they should be prepending the filename. Or, more to the point- splitting the filename and the extension, and inserting the hashes into the middle. E.g., foo.txt becomes foo.QQF523ABC43.txt.

  • LZ79LRU (unregistered) in reply to Medinoc

    I actually ran into a GUID collision in a production DB earlier this year. Brought the whole system down too. Well, not so much crashing as in seemingly unexplainable but very wrong behavior regarding monetary transactions of significant sizes. That one was not fun to track down. I mean, it's just not something you'd ever think about until it happens.

  • (nodebb) in reply to Remy Porter

    I'd have gone with saving the file with just a (rendered) UUID as the name, keeping the mapping from that to the "real" name in a database. Like that, nobody can send a file in and have it arrive somewhere that they have any control over at all (unless the server-side code subsequently decides to allow it).

    And I'd have also used a multi-layer directory structure Just In Case™ because you really don't want to put thousands of files in the same directory on most filesystems deployed out there.

  • (author) in reply to dkf

    That'd be my general leaning, too, though I do see a rationale for including the input filename (but also risks, especially if someone is sending you a carefully malformed filename).

  • (nodebb) in reply to dkf

    because you really don't want to put thousands of files in the same directory on most filesystems deployed out there.

    I was involved with a remediation where around 125000 files were dumped into a single directory on a Windows server. It was seriously time-consuming.

    Please folks, no matter how much you decide to screw up filenames, don't dump all those files in one directory.

  • Adam (unregistered) in reply to Remy Porter
    Comment held for moderation.
  • (nodebb)
    Comment held for moderation.
  • RB (unregistered) in reply to Remy Porter
    Comment held for moderation.
  • Nuitari (unregistered) in reply to dkf
    Comment held for moderation.
  • Conradus (unregistered)
    Comment held for moderation.
  • nz (unregistered) in reply to Remy Porter
    Comment held for moderation.
  • Officer Johnny Holzkopf (unregistered)
    Comment held for moderation.
  • Klimax (unregistered) in reply to Bim Zively

    Meh. On Windows (Server) you can work fairly easy with directory containing few millions of files… (file system will hate you)

  • arweba (unregistered)
    Comment held for moderation.

Leave a comment on “UniQQue Naming”

Log In or post as a guest

Replying to comment #:

« Return to Article