Create unique file or image name before uploading in php

To remove the duplicacy of image some time you need to create a unique name of image while uploading.Here i build a simple function which will you return a unique name .You just need to be copy the entire code below and paste it :



function CreateUniqueName($str){
    list($date, $time) = explode(' ', $str);
    list($year, $month, $day) = explode('-', $date);
    list($hour, $minute, $second) = explode(':', $time);
  
    $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
  
    return $timestamp

 }


Now you need to call this function by passing current date like below and it will return a unique time stamp name in unix format :

Create_uniqueName(date('Y-m-d H:i:s'));


If you like this post please don't forgot to notify me to post a comment .

Happy Coding  guys  :)

Post a Comment

Previous Post Next Post