LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: Jay Savage Date: Tue Feb 19 08:02:54 2008 Subject: Re: Send a file
On Feb 19, 2008 7:15 AM, Beginner <dermot@sciencephoto.com> wrote: > Hi, > > I am trying to send a file in response to a request but am having > trouble. > > Here's what I have so far. I am not certain what the headers should > be. I am not getting any more info from my error_log except Premature > end of script headers. > > > my $s = (stat($file))[7]; > > my $filename = $user.'.csv'; > seek $fh,0,0; > print header(-type=>"text/tab-separated-values",-Content_length=>$s, > -Content_Disposition=>"attachment;filename=$filename"); > print $fh; > close($fh); > > > Can anyone offer some advice? > Thanx, > Dp. > Dermot, I see a couple of things. First, the correct type should be application/x-download or application/octet-stream" The file may *contain* text, but you want the browser to treat the *container* as a stream, not parse it. Second, assuming you're following that normal convention of using $fh to refer to a file handle, "print $fh" will print *to* the filehandle, not read *from* the filehandle and print the contents to standard output. See perldoc -f print for more detail. You probably want something like print while (<$fh>); You could also store the file to an array first, or "slurp" the file, if you want to eliminate the loop. HTH, --jay
| Navigate in group perl.beginners.cgi at sever nntp.perl.org | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by PHP Developer
Powered By PHP Consultants |