Example #1
0
 protected static function unique($path)
 {
     if (File::exists($path)) {
         $ext = File::extension($path);
         $file = File::removeExtension(File::fileName($path));
         $path = File::dirName($path);
         if (preg_match('/(.*)-(\\d+)$/', $file, $matches)) {
             $num = (int) $matches[2] + 1;
             $file = $matches[1];
         } else {
             $num = 1;
         }
         $file = $file . "-" . $num . "." . $ext;
         return static::unique($path . $file);
     }
     return $path;
 }