Handle hostnames with upper-case letters
[webmin.git] / mysql / download.cgi
1 #!/usr/local/bin/perl
2 # download.cgi
3 # Output the contents of a blob field
4
5 if (-r 'mysql-lib.pl') {
6         require './mysql-lib.pl';
7         }
8 else {
9         require './postgresql-lib.pl';
10         }
11 require './view-lib.pl';
12
13 &ReadParse();
14 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
15 @str = &table_structure($in{'db'}, $in{'table'});
16
17 # Get search and limiting SQL
18 ($search, $searchhids, $searchargs) = &get_search_args(\%in);
19 $limitsql = &get_search_limit(\%in);
20 ($sortsql, $sorthids, $sortargs) = &get_search_sort(\%in);
21
22 $d = &execute_sql($in{'db'},
23         "select * from ".&quote_table($in{'table'})." $search $limitsql $sortsql");
24
25 # Work out the MIME type based on the data
26 $data = $d->{'data'}->[$in{'row'}]->[$in{'col'}];
27 if ($data =~ /^\s*(<!doctype|<html|<head|<title)/i) {
28         $type = "text/html";
29         }
30 elsif ($data =~ /^GIF89/) {
31         $type = "image/gif";
32         }
33 elsif ($data =~ /^\377\330\377\340/) {
34         $type = "image/jpeg";
35         }
36 elsif ($data =~ /^%PDF/) {
37         $type = "application/pdf";
38         }
39 elsif ($data =~ /^[\040-\176\r\n\t]+$/) {
40         $type = "text/plain";
41         }
42 else {
43         $type = "application/octet-stream";
44         }
45 print "Content-type: $type\n\n";
46 print $data;
47