Bad file Descriptor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajiv07
    New Member
    • Jun 2007
    • 141

    #1

    Bad file Descriptor

    Hi i have script for upload file to server.when i execute this script it gives Bad file Descriptor error.could u anybody help on this.

    [CODE=perl]
    use strict;
    use CGI;
    use CGI::Carp qw(fatalsToBrow ser);
    use File::Basename;
    use diagnostics;
    $CGI::POST_MAX = 1024 * 1000;
    $CGI::DISABLE_U PLOADS = 0;
    my $query=new CGI;

    my $file = $query->param("file" ) ;
    my $upload_dir = "../templates/";

    my $filename_chara cters = 'a-zA-Z0-9_.-';

    my $file = $query->param('file' ) ;

    $file=~ s/(^\s+|\s+$)//;

    my @array=();

    my ($filename,unde f,$ext) = fileparse($file ,qr{\..*});

    $filename .= $ext;

    $filename =~ tr/ /_/;

    $filename =~ s/[^$filename_char acters]//g;

    if($filename =~ /^([$filename_chara cters]+)$/) {
    $filename = $1;
    }
    else{
    error("The filename is not valid. Filenames can only contain these characters: $filename_chara cters");
    }

    ##I got the error in this line ##

    my $upload_filehan dle = $query->upload("file ") or die $!;

    open (UPLOADFILE, ">$upload_d ir/$filename") or error($!);
    binmode UPLOADFILE;
    while ( <$upload_fileha ndle> ) {
    print UPLOADFILE;
    }
    close UPLOADFILE;
    sub error {
    print $query->header(),
    $query->start_html(-title=>'Error') ,
    shift,
    $query->end_html;
    exit(0);
    }[/CODE]

    Regards
    Rajiv
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by rajiv07
    Hi i have script for upload file to server.when i execute this script it gives Bad file Descriptor error.could u anybody help on this.

    [CODE=perl]
    use strict;
    use CGI;
    use CGI::Carp qw(fatalsToBrow ser);
    use File::Basename;
    use diagnostics;
    $CGI::POST_MAX = 1024 * 1000;
    $CGI::DISABLE_U PLOADS = 0;
    my $query=new CGI;

    my $file = $query->param("file" ) ;
    my $upload_dir = "../templates/";

    my $filename_chara cters = 'a-zA-Z0-9_.-';

    my $file = $query->param('file' ) ;

    $file=~ s/(^\s+|\s+$)//;

    my @array=();

    my ($filename,unde f,$ext) = fileparse($file ,qr{\..*});

    $filename .= $ext;

    $filename =~ tr/ /_/;

    $filename =~ s/[^$filename_char acters]//g;

    if($filename =~ /^([$filename_chara cters]+)$/) {
    $filename = $1;
    }
    else{
    error("The filename is not valid. Filenames can only contain these characters: $filename_chara cters");
    }

    ##I got the error in this line ##

    my $upload_filehan dle = $query->upload("file ") or die $!;

    open (UPLOADFILE, ">$upload_d ir/$filename") or error($!);
    binmode UPLOADFILE;
    while ( <$upload_fileha ndle> ) {
    print UPLOADFILE;
    }
    close UPLOADFILE;
    sub error {
    print $query->header(),
    $query->start_html(-title=>'Error') ,
    shift,
    $query->end_html;
    exit(0);
    }[/CODE]

    Regards
    Rajiv
    In line 38, shouldn't "file" be "$file"?

    Regards,

    Jeff

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Change this line:

      Code:
      open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
      change to:

      Code:
      open (UPLOADFILE, ">$upload_dir$filename") or error($!);
      you already have a trailing slash on the end of $upload_dir as defined in line number eleven of the code you posted.

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by numberwhun
        In line 38, shouldn't "file" be "$file"?

        Regards,

        Jeff
        Short answer is: no.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by KevinADC
          Short answer is: no.
          That's what I get for digging through tons of code all day. :)

          Comment

          • rajiv07
            New Member
            • Jun 2007
            • 141

            #6
            Originally posted by KevinADC
            Change this line:

            Code:
            open (UPLOADFILE, ">$upload_dir/$filename") or error($!);
            change to:

            Code:
            open (UPLOADFILE, ">$upload_dir$filename") or error($!);
            you already have a trailing slash on the end of $upload_dir as defined in line number eleven of the code you posted.
            Thanks Kevin.Its working fine.I have spent 1 hour to sort this but i couldn't find the small mistake.

            Regards
            Rajiv

            Comment

            Working...