• How to generate long unique name for filename

    Passing true as the second parameter to uniqid() will get you to 23chars. md5 will be 32chars. You could also use a UUID library.
    Here's some options:
    uniqid()
    54e6d1765a02a
    
    uniqid('img_')
    img_54e6d1765a0ec
    
    uniqid('', true)
    54e6d1765a1044.98757507
    
    uniqid('img_', true)
    img_54e6d1765a1212.51675326
    
    md5($filename)
    fe6dbefca221b544567d82f830fb9a1e
    
    md5($filename . time())
    329be60060390159f156b229f3acfe4f
    
    md5($filename . microtime())
    f261026e766a32a5f09835154483936d
    
    If you go the md5 route, you should probably use microtime() instead of time() to salt the filename
    Something like this would work too:
    function NewGuid() { 
        $s = strtoupper(md5(uniqid(rand(),true))); 
        $guidText = 
            substr($s,0,8) . '-' . 
            substr($s,8,4) . '-' . 
            substr($s,12,4). '-' . 
            substr($s,16,4). '-' . 
            substr($s,20); 
        return $guidText;
    }
    
    Which outputs
    5AC1949A-6257-E917-43D4-2FB1B222461D
     very easy. add some time stamp into file and md5 hash
    $unique_name = md5($filename. time());
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari