Hail fellow monks,
I have a question as for the best way to open/display and excel or a pdf file in my browser. I have several directories that I search through and when I come to a report, I grab the extension to see what type of report it is(excel/pdf). Then I tried to open the file a couple of ways unsuccessfully. By unsuccessfully, I mean that the adobe acrobat reader tries to open the excel files. When you try and save the file, it comes up as a .pl filetype. I assume that is because my program is a .pl type and it just assumes that the file being opened is the same????

Here is some of my code...Any enlightenment would be appreciated.
$format = &Check_Format($report); &Display_Report($format); sub Check_Format { my $report = $_[0]; my ($name,$format) = split(/\./,$report); return uc($format); } sub Display_Report { my $type = $_[0]; my ($offset,$bytes,$buffer,$contents,$print_pdf); if ($type eq 'XLS') { $print_xls = 'path/to/data/reports'; open(XLS, "$print_xls") || Write_Error($print_xls); $offset = 0; $contents = ''; binmode XLS; until(eof(XLS)) { $bytes += read(XLS,$buffer, 1048576, $offset); $offset += 1048576; $contents .= $buffer; } close XLS; print header(-type => 'application/vnd.ms-excel'); print $contents; } else { if ($type eq 'PDF') { $print_pdf = '/path/to/data/reports'; open(PDF, "$print_pdf") || Write_Error($print_pdf); $offset = 0; $contents = ''; binmode PDF; until(eof(PDF)) { $bytes += read(PDF,$buffer, 1048576, $offset); $offset += 1048576; $contents .= $buffer; } close PDF; print header(-type => 'application/pdf'); print $contents; }
I also tried a simple method of:
print `echo "Content-type: application/pdf"`; print `echo`; print `cat /path/to/data/reports/file.pdf`;
Any help you could offer would be appreciated. Is there a better way to open/display report files.
Prince99

Too Much is never enough...

In reply to displaying excel/pdf files in browser by Prince99

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.