filenames - Generate file name from SHA hash -


i want use output of sha hash generate filename. recommended way that? tried base64 encoding, input results in filename containing forward slashes. prefer method output never contain characters reserved file systems. converting each byte two-digit hex number work, produces shorter output preferable.

you can use this

    function getfilename(){     mt_srand((double)microtime()*10000);    $token=mt_rand(1, mt_getrandmax());    $uid=uniqid(md5($token),true);       if($uid!=false && $uid!='' && $uid !=null){ return $filename =sha1($uid);}        }      //create file name     $filename=getfilename();     $filename = substr($filename, 0, 10); 

the above code uses current system time generate file name , uses mt_rand , md5 create unique file name every time code run. final filename 10 characters, , can adjust whatever number of characters want.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -