If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > trying to convert unix text file to windows text and deliver file in browser..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-05, 22:12
sking sking is offline
Registered User
 
Join Date: Mar 2005
Posts: 5
trying to convert unix text file to windows text and deliver file in browser..

!/usr/bin/perl

$file="../form1/1001du.txt";
open(IN, $file) || die ("can't open file");
&slurpfile ($file);
@fields=split(/\012/, $text);
$newlines=join($/,@fields);
print "Content-type: text/html\n\n";
print $newlines;


print header( -type => 'application/x-download',
-attachment => $ID,
);

#print $_ while (read(DLFILE, $_, 1024));
#close (DLFILE) || die ("Can't close file!");

open(LOG, ">>/home/mortga20/public_html/$subdirectory/log.txt") || die ("Can't open file!");
print LOG "$ID\n";
close (LOG);

print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder;

sub slurpfile {

local( $/, *FH ) ;
open( FH, $file ) or die "unable to read file\n";
$text = <FH>;
}

I tried to get this to work, but to no avail. I'm not sure how to fake the headers to the browser so that it presents the file save as dialog. I'm trying to convert a text file on a unix server to remove the LF character and make it windows compatible. (remove the pesky squares seen in notepad) I open the file, slurp it in, do the split and join, and then I need to present that string in a file save as. Does this routine have to read from a file? Can it use the string I just made? I tried to split and join the file back using $/ as glue. Does anyone know how to make this work?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On