473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

On Perl/CGI

129 100+
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
5 2567
KevinADC
4,059 Expert 2GB
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
chorny
80 Expert
"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
sasimca007
129 100+
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
4,059 Expert 2GB
@chorny
ahhh.... good observation. Welcome to bytes, I see you posting on many perl forums these days,
Jul 22 '09 #5

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

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
13
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
4
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.