Having progressed further with this project, I've discovered that we'd rather not 
allow the user to save the streamed file locally - just allow them to open it via the 
stream.  Is it possible to eliminate or gray-out the "Save" button on the "file 
download" window presented by the browser?  I'd like to just leave "open", "cancel", 
and "more info" as option.  This may not be possible, but thought I'd check...

Thanks.

Jason

-----Original Message-----
From: Shaun Fryer [mailto:[EMAIL PROTECTED]
Sent: Saturday, March 27, 2004 1:12 PM
To: [EMAIL PROTECTED]
Subject: Re: Streaming a file to a remote user


> 4.  Decoded file is streamed to user, who saves the file locally.
> Jason

Below I've provided a starting point to answer your 4th question anyway.
It doesn't have a proper strict style or complete error reporting, but
it does work (last I checked) and should get you started.

-- 
=====================
 Shaun Fryer
=====================
 http://sourcery.ca/
 ph: 905-529-0591
=====================

#!/usr/bin/perl

################################################################################
To download a file via a GET request
http://yourhost.tld/path/to/thisScript.cgi?f=/path/to/fileYouWant
################################################################################

# to restrict which hosts can access this script
# enter your full or partial IP address below
# or comment it out to allow unrestricted access

$remote_ip = '192.168.0.'; 

################################################################################
use CGI;
$q = new CGI;
if ($ENV{REMOTE_ADDR} =~ /^$remote_ip/) {
    if ($q->param('f')) {
        $file = $q->param('f');
        if (!-e "$file") {
            print $q->header,
                  $q->start_html,
                  $file." doesn't exist!",
                  $q->end_html;
        } elsif (!-r "$file") {
            $me = `whoami`;
            print $q->header,
                  $q->start_html,
                  $file." isn't readable by ".$me."!",
                  $q->end_html;
        } else {
            $size = (stat $file)[7];
            $file_name = $file;
            $file_name =~ s/.*\///;
            select STDOUT;
            $| = 1;
            print "Content-Type: application\/force-download\n",
                  "Content-Disposition: attachment\; filename=$file_name\n",
                  "Content-Length: $size\n",
                  "Content-Description: sfryer\'s file downloader\n\n";
            open(OUT,"<$file");
            binmode OUT if (-B "$file");
            $block_size = (stat OUT)[11];
            $block_size = 16384 unless ($block_size);
            while ($length = sysread OUT, $buffer, $block_size) {
                unless (defined $length) { next if $! =~ /^Interrupted/; }
                $written = 0;
                $offset = 0;
                while ($length) { $written = syswrite STDOUT, $buffer, $length, 
$offset; }
                $len -= $written;
                $offset += $written;
            }
            close(OUT);
        }
    }
}
exit 0;
################################################################################

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to