Hi, I need hide real links from users, i write such script, but i'n not support resume downloading ....
here my script:
#!/usr/bin/perl
$| = 1;
use strict;
use Date::Format;
use CGI qw(Fatalstobrouser);
my $filename = "Proklate2.avi";
my $path = "/tmp/upload/";
unless ( -e $path . $filename ) {
print STDERR "No such file! $path$filename";
return 0;
}
my @finfo = stat("$path$filename");
my $filesize = $finfo[7];
my $mfile = $finfo[9];
my $filemtime = time2str( "%D, %d %M %Y %H%i%s %T", $mfile );
open FH, "< $path$filename" or die "Can't open $path$filename: $!";
my $contentSize;
$| = 1;
my $HTTP_RANGE = $ENV{HTTP_RANGE};
if ($HTTP_RANGE) {
my $range = $HTTP_RANGE;
# bytes 7210589-14411430/14411431
$range =~ m/bytes=(\d+)-/;
$range = $1;
$contentSize = $filesize - $1;
warn("cont size is $contentSize and range is $range\n");
my $p1 = $filesize - $contentSize;
my $p2 = $filesize - 1;
my $p3 = $filesize;
seek( FH, $p1, 0 ) or die "Couldn't seek to $p1: $!\n";
print STDOUT "HTTP/1.1: 206 Partial Content\r\n";
print STDOUT "Last-Modified: $filemtime\r\n";
print STDOUT "Cache-Control: None\r\n";
print STDOUT "Pragma: no-cache\r\n";
print STDOUT "Accept-Ranges: byte\r\n";
print STDOUT "Content-Disposition: attachment; filename=\"$filena
+me\"\r\n";
print STDOUT "Content-Range: bytes " . $p1 . "-" . $p2 . "/" . $p
+3."\r\n";
print STDOUT "Content-Length: $contentSize\r\n";
print STDOUT "Proxy-Connection: close\r\n";
print STDOUT "Content-type: application/octet-stream\r\n";
print STDOUT "\r\n";
}
else {
$contentSize = $filesize;
print STDOUT "Last-Modified: $filemtime\r\n";
print STDOUT "Cache-Control: None\r\n";
print STDOUT "Pragma: no-cache\r\n";
print STDOUT "Accept-Ranges: bytes\r\n";
print STDOUT "Content-Disposition: attachment; filename='$filenam
+e'\r\n";
print STDOUT "Content-Length: $contentSize\r\n";
print STDOUT "Content-type: application/octet-stream\r\n";
print STDOUT "Proxy-Connection: close\r\n";
print STDOUT "\r\n";
}
binmode FH;
my $buffer;
STREAM:
while ( read( FH, my $buffer, 65536 ) ) {
last STREAM unless print STDOUT $buffer;
}
close FH;
But log of sended headers:
25 16.12.2006 14:45:28 GET /cgi-bin/downl.pl HTTP/1.0
User-Agent: Download Master
Accept: */*
Referer: http://localhost/cgi-bin/
Range: bytes=391001341-
Pragma: no-cache
Cache-Control: no-cache
Host: localhost
26 16.12.2006 14:45:28 HTTP/1.1 200 OK <-----------------HERE IS STRA
+NGE(not my ) HEADER
Date: Sat, 16 Dec 2006 12:45:28 GMT
Server: Apache/1.3.33 (Cygwin)
Accept-Ranges: byte
Cache-Control: None
Content-Disposition: attachment; filename="Prok
+late2.avi"
Content-Range: bytes 391001341-734490623/734490
+624
HTTP/1.1: 206 Partial Content<---HERE IS CORREC
+T HEADER
Pragma: no-cache
Proxy-Connection: close
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Content-Length: 343489283
Connection: close
Content-Type: application/octet-stream
Than script sends 200 OK response, but I need 206.
Can you please advice how to make workaround for this?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.