use CGI;
 $query = new CGI;
 my $filePath   = $query->param( 'filepath' ) || "";
  my $tmpFilename = $query->tmpFileName( $filePath ) || "";

  # check if file exists and has non zero size
  if( ! -s "$tmpFilename" ) {
    my $url = getOopsUrl( "oopsupload", $filePath );
    print $query->redirect( $url );
    return;
  }

  # cut path from filepath name (Windows "\" and Unix "/" format)
  my @pathz = ( split( /\\/, $filePath ) );
  my $filetemp = $pathz[$#pathz];
  my @pathza = ( split( '/', $filetemp ) );
  my $fileName = $pathza[$#pathza];
  $fileName =~ s/[^A-Za-z0-9_\.\-]//go;  # delete special characters

  # save uploaded file
  my $newFile = "/path/to/public/folder/$fileName";
  `cp $tmpFilename $newFile`;
  umask( 0027 );
  chmod( 0644, $newFile );