This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Uploading Files In Perl

Dear all,

I am trying to upload a file from my HTML form using PERL CGI. The problem is that the file gets created in the server directory but its uploaded as an empty file(o bytes).

Below is my code. As I am a fresher to PERL, please can someone help me out with uploading the file with its contents.

#!C:/Perl64/bin/perl.exe -w

no strict;
use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;

my $q = new CGI;

my $upload_dir = "C:/Apache24/htdocs/files" ;

my $safe_filename_characters = "a-zA-Z0-9_.-";

$q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_error );
my $file      = $q->param( "seq" )     || error( $q, "No file received." );
my $fh        = $q->upload( $file );
my $evalue    = $q->param( "evalue");
my $identity  = $q->param( "identity");

$file =~ tr/ /_/; 

$file =~ s/[^$safe_filename_characters]//g;
#$file=~m/^.*(\\|\/)(.*)/; 

my ( $name, $path, $extension ) = fileparse ( $file, '\..*' ); 

$file = $name . $extension;

open ( UPLOADFILE, ">$upload_dir/$file" ) or die "$!";

while ( <$fh> ) 
{ 
  print UPLOADFILE $_; 
} 
close UPLOADFILE;
deleted-post

I will undelete and close this question. The sole reason for doing so is to demonstrate users the type of questions that should be asked elsewhere. Deleted questions are not visible to non-moderators.

0 answers

No answers yet.

Log in to answer this question.