File: mime.php

package info (click to toggle)
phabricator 0~git20190207-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 71,728 kB
  • sloc: php: 552,244; sql: 16,997; ansic: 3,619; yacc: 2,503; sh: 754; xml: 519; lex: 488; cpp: 221; python: 186; makefile: 177; sed: 66
file content (40 lines) | stat: -rwxr-xr-x 881 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env php
<?php

require_once dirname(__FILE__).'/../__init_script__.php';

$args = new PhutilArgumentParser($argv);
$args->setTagline(pht('test %s', 'Filesystem::getMimeType()'));
$args->setSynopsis(<<<EOHELP
**mime.php** [__options__] __file__
    Determine the mime type of a file.
EOHELP
  );
$args->parseStandardArguments();
$args->parse(
  array(
    array(
      'name'  => 'default',
      'param' => 'mimetype',
      'help'  => pht(
        'Use __mimetype__ as default instead of built-in default.'),
    ),
    array(
      'name'     => 'file',
      'wildcard' => true,
    ),
  ));

$file = $args->getArg('file');
if (count($file) !== 1) {
  $args->printHelpAndExit();
}

$file = reset($file);

$default = $args->getArg('default');
if ($default) {
  echo Filesystem::getMimeType($file, $default)."\n";
} else {
  echo Filesystem::getMimeType($file)."\n";
}