Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Inconsistent Perl code in Internet Explorer 8

by ThePole (Initiate)
on Mar 06, 2012 at 07:10 UTC ( #958025=perlquestion: print w/ replies, xml ) Need Help??
ThePole has asked for the wisdom of the Perl Monks concerning the following question:

Dear Holy Monks, please advise on the following.

I have a piece of Perl code to do uploading into the database. It works on Internet Explorer 8 of other users but failed on one with the error: Malformed Multipart POST method: data truncated. It works with FireFox however on that user. I would like to know if there are something not well with the code or is purely a browser issue. I have tried repairing, reinstalling Internet Explorer 8 but the error just keep appearing for the user. Using Fiddler shows the error "The Server did not return properly formatted HTTP headers. HTTP headers should be terminated with CRLFCRLF. These were terminated with LFLF". I am thus unsure is the problem with IE or the Perl code. The code in question is:

$|=1; my $data = $q->param("ATTACHMENT_FILE"); #&cgierr("File 0:".$data); # write original file # -------------------------------------------------------- if($data) { my $max_size = 50000; #in kb # read file extension # -------------------------------------------------------- my ($file_obj,$file_ext) = split(/\./,$data); $file_ext = lc($file_ext); #unrelated SQL statements removed for clarity my $directory = "$c{base}{path}/folder/".theYear.theMonth. +refNo; $directory =~ s/\\/\//g; if (!(-e $directory)) { mkdir ($directory, 0755); } $directory =~ s/\\/\//g; &cgierr("Directory does not exist! : $directory\n") if (!( +-e $directory)); &cgierr("Permissions denied! : $directory\n") +if (!(-W $directory)); &cgierr("Specified path is not a directory! : +$directory\n") if (!(-d $directory)); my ($filename,$fullfile); ($directory =~ m,/$,) ? ($fullfile = "$directory$data") : ($fullfile = "$directory/$data"); my ($bytesread, $buffer, $file_size); $file_size = 0; open(OUTFILE,">$fullfile"); binmode( OUTFILE ); while ($bytesread = read($data,$buffer,1024)) +{ print OUTFILE $buffer; $file_size += 1024; } close(OUTFILE); chmod (0666, "$fullfile");

Comment on Inconsistent Perl code in Internet Explorer 8
Download Code
Re: Inconsistent Perl code in Internet Explorer 8
by JavaFan (Canon) on Mar 06, 2012 at 07:17 UTC
    Your code does not compile (for starters, the if block is never terminated), nor does it send any headers.

    What makes you think whatever problem you have is in the lines you posted?

    And please, use some sane identation.

Re: Inconsistent Perl code in Internet Explorer 8
by Anonymous Monk on Mar 06, 2012 at 07:19 UTC

      Dear Sirs, thank you for your reply.

      I am actually a VB/Java programmer, so am very new to Perl. This code was done by a friend, but he insists that there is nothing wrong, since other users are working. But if that is the case, then it shouldn't have the error in Fiddler. I am really at wits end for this.

      By the way, how does code printing headers looks like?

        This code was done by a friend, but he insists that there is nothing wrong,

        Well, aside from the notes by JavaFan, the code is broken. It makes assumptions about the value of $data, and the big mistake, it trusts the user not to be malicious. The value of $data can vary from browser to browser. My first link and the links it links, deal with this in some detail. Read it.

        By the way, how does code printing headers looks like?

        Read my links, there are at least 3 examples, and they all contain the word "header"

        If your friend thinks this is good Perl code, then you might want to get a new Perl programmer (or a new friend).

        Aaron B.
        My Woefully Neglected Blog, where I occasionally mention Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://958025]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-08-01 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls