Solved

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

Posted on 2006-06-13
2
306 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

730 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