What is a good way to generate short and unique file / folder names?

The criteria are mainly as follows:

  • folders will exist for about 24-48 hours
  • folder names cannot be easily guessed by the user (if used in the URL)
  • folder names must be short 5-15 characters

Initial thoughts:

printf('%u',crc32(microtime(true)));

More: When uploading a file, I basically want to save the unique file name as named by the bootloader, so to avoid a name clash, I would like to put it in a directory with a unique name ...

+3
source share
8 answers

[] . PHP id. .

+6

:

  + uploader-name  
    + 20090401
      + 010000     // hhmmss
      + 013000     // hhmmss
      + 014500     // hhmmss
    ...

    + 20090402

, "a", "b", "c",... .. .

. , .

, . ( PHP), , , , .

, - "2009-Apr-01", "01:45 AM" ..

+1

, Ruby :

require 'digest/md5'
Digest::MD5.hexdigest(Time.now.to_s)

=> "f531384b3cc8c60b7c5b7ad087cb0ae4"
0

" ". , , ( ) , , , . , "".

0

0

- :

$salt='Whatever you want';
$folderName=SHA1($salt.date('U'));

('U') Unix Epoch (1 1970 00:00:00 GMT), , , , .

$salt ( ..).

0

( md5, sha) , , . , , script, , , , . , , .

OP, . , . 5 , - , . 15 , , , .

0

++ tmpfile tmpnum, cstdio (stdio.h), . tmpfile . , , , .

0

Source: https://habr.com/ru/post/1707447/


All Articles