-    ( $newest_name, $newest_time ) = ( $file, -M _ )
-        if( ! defined $newest_time or -M $path < $newest_time );
-    }
-  $latest_file_name = $complete_path .'/' . $newest_name;
-  my $filesize = stat($latest_file_name)->size;
-
-  # prüfung auf identisch oder nicht
-  my ($ext) = $form->{tmpfile} =~ /(\.[^.]+)$/;
-  my $current_file = join('/', $form->{tmpdir}, $form->{tmpfile});
-  my $current_filesize = stat($current_file)->size;
-  if ($current_filesize == $filesize) { # bei gleicher größe copy deaktivieren
-    $main::lxdebug->leave_sub();
+    ( $newest_name, $newest_time ) = ( $file, -M _ ) if( ! defined $newest_time or -M $path < $newest_time );
+  }
+
+  closedir $dh;
+
+  $latest_file_name    = File::Spec->catfile($complete_path, $newest_name);
+  my $filesize         = stat($latest_file_name)->size;
+
+  my $current_file     = File::Spec->catfile($form->{tmpdir}, apply { s:.*/:: } $form->{tmpfile});
+  my $current_filesize = -f $current_file ? stat($current_file)->size : 0;
+
+  if ($current_filesize == $filesize) {
+    $::lxdebug->leave_sub();