#!/usr/bin/perl

my $inputFile = shift;
my $mime = shift;
my $outputDir = shift;

my $inputDir = "";
if( $inputFile =~ m/^(.*)[\/\\]([^\/\\]*)$/ ) {
	$inputDir = $1;
	$inputFile = $2;
}

print qq|Input File: $inputFile\n|;
print qq|MIME type: $mime\n|;
print qq|Output Dir: $outputDir\n|;
print qq|Input Dir: $inputDir\n|;

my $token = "up_$inputFile";

system("cp $inputFile $outputDir/$token");

CreateInfoFile($outputDir,$token,$inputFile,$mime);

sub CreateInfoFile {
	my $uploadDir = shift;
	my $token = shift;
	my $originalFileName = shift;
	my $mime = shift;

	my $fileName = "$uploadDir/${token}.info";
	open(FILE, "> $fileName") or die("Can not open file $fileName for writing");

	print FILE qq|$mime\n|;
	print FILE qq|$originalFileName\n|;
	print FILE qq|\n|;
	print FILE qq|\n|;
	print FILE qq|\n|;

	close FILE;
}
