Hi Monk
I have a cgi script which has a "a href" tag link on it and below that link a table containing some data. The link is for creating an excel report which will contain the table data on that page.
Now in the background , clicking on that link , it redirects to another script (createReport.pl)and generates the excel report. Now I want to download that report also , but that is not working.

My cgi script is below :

use CGI; my $cgi = CGI->new (); my $js = <<'JS'; function reportCreate() { var currenturl = document.URL; var url = "https://autoreport.com:8001/cgi-bins/createReport.pl?url="+ +currenturl; window.location.href = url ; return 1; } JS print qq{<script type = "text/javascript">$js</script>}; print $cgi->a({-href=>"javascript:void(0);", -onclick => "reportCreate +();" }, 'Create Report <br>'); print qq{<TABLE BORDER=1><TR BGCOLOR="#D0D0D0"><TH ALIGN=LEFT NOWRAP +>Name}; print qq{</TH>}; ## some Table html code here...please assume print qq{</TABLE>};

Now the above code is working fine. Below I am givnig the createReport.pl script to which the above script redirects. createReoprt.pl is creating the excel sheet report and pushing the content of the table inside it successfully. But I am concerened about the code below that for downloading which is not working.

use Spreadsheet::WriteExcel; use HTML::TableExtract qw(tree); require LWP::UserAgent; my $filename = "/home/user/report.xls"; # The excel generation using Spreasheet # The table extraction as element using TableExtract # All fine till now , and the excel is getting generated # with the desired content. # But this below piece of code is not working, please let me know how + to make it work : open(FILE, "<$filename ") || die "Unable to download file \n"; my @fileholder; binmode FILE; @fileholder = <FILE>; close (FILE); print "Content-Type:application/vnd.ms-excel\n"; print "Content Disposition:attachment;filename=report.xls\n\n"; print @fileholder;

Please help.


In reply to How to download a file from the server by ghosh123

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.