By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,775 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,775 IT Pros & Developers. It's quick & easy.

On Perl/CGI

100+
P: 129
Hai friends,
I have one doubt that if we click a link then a prompt should come as Open file (or) Save file and if we click Save file the file should be downloaded into the default path of the current system.

in perl i written the code as below:
Expand|Select|Wrap|Line Numbers
  1. use Text::CSV;
  2. use Apache::Request;
  3. use Apache::File;
  4.  
  5. sub handler
  6. {
  7.     my $r = Apache::Request->new(shift);
  8.     my $download = $r->param('download');
  9. if($download eq '' )
  10. {
  11. print <<HTML;
  12. <html>
  13.     <head>
  14.         <script type='text/javascript'>
  15.             function transfer(frm)
  16.             {
  17.                 var url = 'http://10.202.1.22/practice/newldap?download=yes';
  18.                 document.frm.action = url;
  19.                 document.frm.submit();
  20.             }
  21.         </script>
  22.  
  23. # In this area a csv file is created
  24.  
  25.             <a href='javascript:transfer(this.form)' class='Download'>File in CSV Format</a>
  26.         </form>
  27.         </center>
  28.     </body>
  29. </html>
  30. HTML
  31. }
  32. elsif($download eq 'yes')
  33. {
  34.     # To make the browser for downloading the file
  35.  
  36.     $r->send_http_header('application/vnd.ms-excel');
  37.     open FH, "</tmp/$date.csv";
  38.     my $le = $r->send_fd(FH);
  39. }
  40.  
  41. return OK;
  42. }
  43. 1;
  44.  
The above code is working but when it comes to CGI/Perl programming how can i do that, it would be helpful if anybody replied with sample code.
It is very urgent friends, please help me.
Jul 21 '09 #1
Share this Question
Share on Google+
5 Replies


KevinADC
Expert 2.5K+
P: 4,059
The code you posted is perl, and it appears to be a CGI script, so if it works then you are already using perl and CGI to accomplish the task.
Jul 21 '09 #2

Expert
P: 80
"use Apache::Request;" line tells me that this program is written to run under mod_perl only. To rewrite this as CGI program, you need to use CGI.pm instead of Apache::Request.
Jul 21 '09 #3

100+
P: 129
Yes that's what i want, i am using modperl and with Apache::Request, but when i write use CGI and not Apache::Request, it comes to CGI and in that what is the relavant code to a file to be downloaded when i click a link. Anyone give with example.
Jul 22 '09 #4

KevinADC
Expert 2.5K+
P: 4,059
@chorny
ahhh.... good observation. Welcome to bytes, I see you posting on many perl forums these days,
Jul 22 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.