Solved

THIS CGI CODE DOES NOT output as csv file.PLS HELP

Posted on 2006-06-13
2
307 Views
Last Modified: 2012-08-14
hi Experts

i need some help with this code

this code actually generates some data which should be dowloaded as csv file.. but the problem with this code is.. it dowloads as evpData.cgi instead of evpdatA.CSV

CAN ANYONE PLEASE MODIFY THE CODE SO THT IT IS DOWNLOADED AS CSV FILE

ITS URGENT .. PLS HELP..
---------------------------------------------------------------------------
#!/bin/env perl

#print "Content-type: application/vnd.ms-excel\n\n";
#print "Content-type: application/csv.ms-excel\n\n";
#print "Content-type: application/comma-separated-values\n\n";
#print "Content-type: text/comma-separated-values\n\n";
print "Content-type: text/csv\n\n";

require "../cgi-lib.pl";
require "../ppdInclude.pl";
&ReadParse;

my $xLat = sprintf("%s%s", $in{'decDegreesLong'},
$in{'decMinutesLong'});
my $yLong= sprintf("%s%s", $in{'decDegreesLat'}, $in{'decMinutesLat'});

#if ($x < 112 || $x > 154) {
#        print "longitude values are 112..154 inclusive\n\nYour value is
$x\n";
#        exit();
#}
#
#if ($y < -44 || $y > -10) {
#        print "latitude values are -10..-44 inclusive\n\nYour value is
$y\n";
#        exit();
#}

# make the latitude and longitude are in 0.05 degree granularity
my $yy= int(($yLong-0.025)*20);
$y=-$yy/20.0;

$x= int(($xLat-112+0.025)*20);

my $datafile;
$datafile="data/output_dir_by_lat/$yLong";

my @bits;
open(INPUT, $datafile) or die "Can't find datafile $datafile: $!\n";

        print ",Monthly\n";
        print ",Evaporation\n";
        print ",(mm)\n";
print ",\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "January,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "February,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "March,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "April,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "May,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "June,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "July,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "August,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "September,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "October,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "November,",
"$bits[$x]\n";
$_=<INPUT>; @bits = split(' ', $_, 9999); print "December,",
"$bits[$x]\n";

while (<INPUT>) {
        my @bits = split(' ', $_, 9999);
        print "$bits[$x]\n";
}
------------------------------------------------------
0
Comment
Question by:GouthamRDodda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Expert Comment

by:OliWarner
ID: 16899914
Setting the content type will not get around the filename, only which application the browser thinks to open it with.

To do that you need to look into URL rewriting. If you're using apache, this should be really easy... If you dont know what it is, URL Rewriting is having a fake URL that maps onto a real file... In your case: whatever.csv maps onto your .cgi file.

All you need to do (with a bit of editing of course) is put the following in a file called .htaccess in your root directory:
RewriteEngine on
RewriteRule   ^/evpData.csv$  evpData.cgi  [R]

So when you request evpData.csv from the server, you get the output of the CGI file. The browser wont know that its being fed from the cgi file and therefore will attempt to name it a .csv
0
 
LVL 6

Accepted Solution

by:
nitinsawhney earned 500 total points
ID: 16900222
Hi,

Try changing your headers to following:

        print "Content-type: text/html\n";
        print "Content-Disposition: attachment; filename=$name.csv\n\n";

Here $name could be anything for e.g. evpData

Hope this helps.

Cheers!!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question