How to create a unique name (hash) to save photos? I have here so

$format_avatar = explode(".", $_FILES['image']['name']); $name_photo = md5(uniqid(rand(),1)) .'.'. $format_avatar[1]; 

It may be better to have a user id and photo number.

 $format_avatar = explode(".", $_FILES['image']['name']); $name_photo = md5($id . ++$countPhoto .'.'. $format_avatar[1]; 
  • What exactly does “unique” mean? Unique in what limits? If you mention the word hash: how often are collisions resolved (and are they allowed at all)? - VladD
  • something in the same folder and in the database is not repeated. - Zow
  • Guaranteed not to repeat? Or is it only with some probability? - VladD
  • guaranteed. - Zow

1 answer 1

This counter is guaranteed, and you will hardly reach the ceiling of any bigint in the foreseeable future (and boundless too)