private function autoNumberFile($path, $file)
    {
        $extension = $file->getClientOriginalExtension();
        $original_name = $file->getClientOriginalName();
        
        $filename = $original_name; // Set to original name
        
        $counter = 1;
        while (file_exists($path . '/' . $filename)) {
            $filename = str_replace("." . $extension, '_' . $counter . "." . $extension, $original_name);
            $counter++;
        }
        
        return $filename;
    }
private function autoNumberFile($path, $file)
    {
        $extension = $file->getClientOriginalExtension();
        $original_name = $file->getClientOriginalName();
        
        $filename = $original_name; // Set to original name
        
        $counter = 1;
        while (file_exists($path . '/' . $filename)) {
            $filename = str_replace("." . $extension, '_' . $counter . "." . $extension, $original_name);
            $counter++;
        }
        
        return $filename;
    }
private function autoNumberFile ( $ path , $ file ) { $ extension = $ file -> getClientOriginalExtension ( ) ; $ original_name = $ file -> getClientOriginalName ( ) ; $ filename = $ original_name ; // Set to original name $ counter = 1 ; while ( file_exists ( $ path . '/' . $ filename ) ) { $ filename = str_replace ( "." . $ extension , '_' . $ counter . "." . $ extension , $ original_name ) ; $ counter ++ ; } return $ filename ; }
Automatically appends number if file already exists
@param  string $path
@param  string  $filename
@return string New Filename
Automatically appends number if file already exists