Apart from whatever header trickery you had to make to force IE to do what you want there are three more problems with the code!

First, you did not binmode() neither STDOUT nor NEWFILE. While this might possibly work well under a Unix it will definitely break under Windows and may well break under Unixes too with some system and perl settings. By default files are opened in "text" mode, which may mean conversions of line end characters, conversions to or from utf8 and so forth. If you are working with binary data, do use binmode(FILEHANDLE). Always.

Second, you read the whole file into a list, splitting it on newlines (the file is binary, there is no notion of lines there, the newline characters inside are purely accidental!) and then print all elements of the array. This means that the amount of memory you need it proportional to the size of the file. That's not a good thing. You should read the file in chunks (4KB sounds like a reasonable size to me) and print the chunks.

... binmode(STDOUT); open(NEWFILE,"<", "/tmp/$filename") or report_problem("Can't open the +file: $^E"); binmode(NEWFILE); my $buff; while (sysread(NEWFILE,$buff, 4*1024)) { print $buff; } close(NEWFILE);

Then there's another important problem. Security. Imagine someone sends your script conid=../etc/passwd%00. The filename parameter will be completely unimportant in this case since once the filename is passed to the system functions all the stuff after the \x00 character is ignored. This means that you'll dutifully send the hacker your /tmp/../etc/passwd, that is, your /etc/passwd. Erm ... probably not what you intended, right?


In reply to Re: Opening Excel from CGI Program by Jenda
in thread Opening Excel from CGI Program by pankaj_it09

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.