Saving a file to a Particular Server Location

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chittaranjan
    New Member
    • Sep 2006
    • 51

    Saving a file to a Particular Server Location

    Hi All,

    I want to save a file in a given location in server which takes data from my form and save that as a tab separated *.txt file, where I am able to generate the tsv file but to save I am not able to do. I want while I will hit submit then it should save that file to the location I want by taking all the data. If any kind of help then highly acceptable.

    Thanks and Regards,
    Chittaranjan :)
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    If using the CGI module (which you should be) read the CGI documentation:

    perldoc CGI module

    Comment

    • Chittaranjan
      New Member
      • Sep 2006
      • 51

      #3
      Kevin,

      Thank you a lot for your quick response and I am able to save the file to the server but now the problem is that after saving the file I want to make the form stay at the last position but it is going to a new blank screen any help please....

      Thanks,
      Chittaranjan :)

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        I will need to see your code if you want help.

        Comment

        • Chittaranjan
          New Member
          • Sep 2006
          • 51

          #5
          Yes I know if I can able to show you the code then that will help me but that is a very big file how to show at here I am not able to understand after all I am having some part of the functions I have hope that will work.

          Code:
          if ( $q->param('confirm') ) {
          
          	if ( $self->{'download'} ) {
          		my $no = $q->param("noOfItems");
          		my $tloc = $q->param("noOfLocations");
          		# send the file to user
          		print $thisForm->processFormFinalDeliverData( $no, $tloc );
          		exit 1;
          	}
          
          } elsif ( $q->param('confirmsend') ) {
          	if ( $self->{'download'} ) {
          		my $no = $q->param("noOfItems");
          		my $tloc = $q->param("noOfLocations");
          		my $upload_dir = "/autoweb/data/ess/MMCXTEST/forms";
          
          		# send the file to user
          		#my $data = $thisForm->processFormFinalDeliverData( $no, $tloc );
          		#&downloadFileSend( $self->{'formid'}, $data, $uid );
          		#my $act = "process";
          		#$thisForm->onSend( $self->{'formid'}, $no, $tloc, $act );
          		#print $thisForm->processFormFinalDeliverData( $no, $tloc );			
          		my @success = ();
          		my $tsvdata = $thisForm->processFormFinalDeliverData( $no, $tloc );
          		my $filename = &downloadFileSend( $self->{'formid'}, $uid );
          		$filename =~ s/.*[\/\\](.*)/$1/;
          
          		open UPLOADFILE, ">$upload_dir/$filename" or die "Can't open $filename: $!";
          		print UPLOADFILE "$tsvdata";
          		close (UPLOADFILE) || die "Can't close $filename";
          		#$thisForm->onSend();
          		if (-s "$filename" >= 0) {
          			$thisForm->onSend();
          		}
          		#print $q->header('text/html'),
          		#$q->start_html(-title=>'Thanks!',bgcolor=>'#FFFFFF');
          		#if (@success) {
          		#	print qq~<h3>@{[scalar @success]} files successfully uploaded:</h3>~;
          		#}
          		exit 1;
          	}
          }
          Here are two button calls where I am doing the file download in the first
          if ( $q->param('confirm ') )
          That works fine which allow me to save the file to my local system with the dialog box for open or save. But in the second I want to save the file to the server. Where it saves that but after saving the file it takes the page to a new blank screen where I want to stay at the confirm screen.
          Here are the code I think having some relation to that.

          Code:
          sub downloadFileName {
          	warn 'downloadFileName';
          	my $fId = shift(@_);
          	my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime time;
          	if ( $mon < 10 ) {
          		$mon = "0" . ( $mon + 1 );
          	} else {
          		$mon = $mon + 1;
          	}
          	if ( $mday < 10 ) {
          		$mday = "0" . $mday;
          	}
          	my $opfile = sprintf "%s_%s%s%s%s%s%s.txt",$fId,( $year + 1900 ),$mon,$mday,$hour,$min,$sec;
          
          	return $opfile;
          }
          
          =item downloadFileSend
          
          Generate a file in /autoweb/data/ess/MMCXTEST/forms directory and
          with the user id with the file name for the Sent file
          
          =cut
          
          sub downloadFileSend { warn 'downloadFileSend';
          	my $fId = shift(@_);
          	#my $data = shift(@_);
          	my $uid = shift(@_);
          	#my $upload_dir = "/autoweb/data/ess/MMCXTEST/forms";
          	my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime time;
          	if ( $mon < 10 ) {
          		$mon = "0" . ( $mon + 1 );
          	} else {
          		$mon = $mon + 1;
          	}
          	if ( $mday < 10 ) {
          		$mday = "0" . $mday;
          	}
          	my $opfile = sprintf "%s_%s_%s%s%s%s%s%s.txt",$uid,$fId,( $year + 1900 ),$mon,$mday,$hour,$min,$sec;
          
          	#my $filename = $opfile;
          	#$filename =~ s/.*[\/\\](.*)/$1/;
          	#open UPLOADFILE, ">$upload_dir/$filename" or die "cannot open $filename: $!";;
          	#print UPLOADFILE "$data";
          	#close UPLOADFILE;
          	return $opfile;
          }
          
          sub extraheaders {
          	warn 'extraheaders';
          	my $self = shift;
          	my ($q) = @{$self}{'query'};
          	my %headers;
          	if (defined($q->param('confirm'))) {
          		$headers{'-attachment'} = &downloadFileName($self->{'formid'});
          		return %headers;
          	} #elsif (defined($q->param('confirmsend'))) {
          	# $headers{'-attachment'} = &downloadFileName($self->{'formid'});
          	# return %headers;
          	#}
          	else {
          		$self->SUPER::extraheaders(@_);
          	}
          }
          
          =item contenttype($q,$a)
          
          contenttype is uses to set the MIME content-type HTTP header.
          set based on the request parameters - when a file download is requested
          
          =cut
          
          sub contenttype { warn 'contenttype';
          	my $self = shift;
          	my $q = shift;
          	my $a = shift;
          
          # initialize the state
          	$self->initializeProcess($q);
          
          	if ($self->{'download'}) {
          		return "text/plain";
          	}
          
          	$self->SUPER::contenttype(@_);
          }
          Hope this much will help me for shutting out the problem.

          Thanks,
          Chittaranjan
          Last edited by miller; Apr 12 '07, 01:52 AM. Reason: Reformatting

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Sorry, I can't tell by looking at that code. If you want to display the confirmation page you either need to redirect to that page or manually print it out to the screen.

            Comment

            • Chittaranjan
              New Member
              • Sep 2006
              • 51

              #7
              Originally posted by KevinADC
              Sorry, I can't tell by looking at that code. If you want to display the confirmation page you either need to redirect to that page or manually print it out to the screen.
              Thanks,

              I will try to figure out a way to solve you as reference to your suggestion.

              Chittaranjan:)

              Comment

              Working...