OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/perl -wT |
| 2 |
| 3 use strict; |
| 4 |
| 5 use CGI; |
| 6 use File::stat; |
| 7 |
| 8 my $query = new CGI; |
| 9 |
| 10 my $name = $query->param('name'); |
| 11 my $filesize = stat($name)->size; |
| 12 |
| 13 # Get MIME type. |
| 14 my $type = $query->param('type'); |
| 15 if (!$type) { |
| 16 print "Status: 400 Bad Request\r\n"; |
| 17 return; |
| 18 } |
| 19 |
| 20 my $rangeEnd = $filesize - 1; |
| 21 |
| 22 # Print HTTP Header, disabling cache. |
| 23 print "Cache-Control: no-cache\n"; |
| 24 print "Content-Length: " . $filesize . "\n"; |
| 25 print "Content-Type: " . $type . "\n"; |
| 26 |
| 27 print "\n"; |
| 28 |
| 29 open FILE, $name or die; |
| 30 binmode FILE; |
| 31 my ($data, $n); |
| 32 my $total = 0; |
| 33 my $break = $filesize / 4; |
| 34 my $string = "corrupt video"; |
| 35 seek(FILE, 0, 0); |
| 36 |
| 37 while (($n = read FILE, $data, 1024) != 0) { |
| 38 print $data; |
| 39 |
| 40 $total += $n; |
| 41 if ($total >= $filesize) { |
| 42 last; |
| 43 } |
| 44 |
| 45 if ($total >= $break) { |
| 46 print $string; |
| 47 $total += length($string); |
| 48 } |
| 49 |
| 50 } |
| 51 close(FILE); |
OLD | NEW |