The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Downloading file from internet chetanpc Shell Programming and Scripting 4 03-25-2008 04:36 PM
Downloading a csv file automatically figaro Shell Programming and Scripting 2 03-19-2008 05:36 PM
Script to generate text file from excel file isingh786 UNIX for Dummies Questions & Answers 1 01-24-2008 10:32 AM
How to attach an excel file/ dat file thru unix mails diwakar82 Shell Programming and Scripting 1 01-06-2006 11:23 AM
how can i read an excel file using C? DebianJ High Level Programming 6 07-01-2005 02:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-15-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Downloading Excel File

Hello All,

Currently working with CGI scripts in perl which involves
a) uploading
b) processing
c) downloading the file back to the user

uploading and processing quite trivial and they are done

Third part is kind of being tricky.
Excel file in binary format is getting displayed in the html page itself and not popping up a download window for downloading file to the client's machine

Code snippet
Code:
my @fileholder;

open(EXCLFILE, "<", $file_path) or die "Unable to download file $file_path\n";
 binmode EXCLFILE;
 @fileholder = <EXCLFILE>;
close (EXCLFILE);

print "Content-Type:application/vnd.ms-excel\n";
print "Content-Disposition:attachment;filename=$file_path\n\n";
print @fileholder;
Any pointers to proceed with this is much appreciated.

Thanks

Last edited by matrixmadhan; 01-15-2008 at 12:43 PM..
  #2 (permalink)  
Old 01-15-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,322
put "application/octet-stream" instead of "vnd.ms-excel" , it should work. Else, look at these thread, it may help.
  #3 (permalink)  
Old 01-15-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
This is completely running over my head.

I did went through the link provided in perlmonks and tried it,
but its refusing to work

Please find the snippet below

Code:
my $cgi = new CGI;

  open(DLFILE, "<$abs_path") || die "Unable to download file $abs_path\n";
  print $cgi->header(
    '-type' => "application/octet-stream; name=$filename",
    '-Content-Disposition' => "attachment; filename=$abs_path",
    '-Content-Transfer-Encoding' => "binary");
    binmode DLFILE;
    print while(<DLFILE>);
  close (DLFILE);
Ex:
Code:
$abs_path = "/home/matrix/file.xls";
$filename = "file.xls";
No way, a download pop up window is up
and all the binary contents of the excel file is displayed as such in the html page.

Any pointers again, much appreciated
  #4 (permalink)  
Old 01-16-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,322
Code:
use strict;
use CGI qw /:standard /;
my $query = new CGI;
print $query->header(-type=>"application/vnd.ms-excel",-attachment=>"path/file.xls",-Content_length=>" -s path/file.xls");
open (FH, "path/file.xls");
print $_ while <FH>;
close (FH);
- found it on internet, i'm not sure if it's going to work. Strange, that the content type is not honored, even though it's forced to be binary-octet-stream. Another try : setup wrong type like :"bad-file-type" and this should pop-up. Last resort is to put MIME type in apache's config -
Code:
AddType application/vnd.ms-excel .xls
  #5 (permalink)  
Old 01-16-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Thanks for the reply Sysgate.

I already have the specified MIME type in mime configuration file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0