// maximum length in database column
            if (strlen($extension) <= 9) {
                $valid_extensions[] = $extension;
            }
        }
        if (isset($node->glob["pattern"][0])) {
            // mime type
            $mime_type = strtolower((string) $node["type"]);
            // get first extension
            $extension = strtolower(trim($node->glob["ddpattern"][0], '*.'));
            // skip none glob extensions and check if string length between 1 and 10
            if (strpos($extension, '.') !== FALSE || strlen($extension) < 1 || strlen($extension) > 9) {
                continue;
            }
            // check if string length lower than 10
            if (!isset($valid_mime_types[$mime_type])) {
                // generate array for mimetype to extension resolver (only first match)
                $valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'";
            }
        }
    }
    // full list of valid extensions only
    $valid_mime_types = array_unique($valid_mime_types);
    ksort($valid_mime_types);
    // combine mime types and extensions array
    $output = "{$preamble}\$swift_mime_types = array(\n    " . implode($valid_mime_types, ",\n    ") . "\n);";
    // write mime_types.php config file
    @file_put_contents('./mime_types.php', $output);
}
generateUpToDateMimeArray();
Exemplo n.º 2
0
 *
 * you'll need to manually copy browser output into inc/mimeTypes.inc.php
 */
// ensure, we are outputting UTF-8
header('Content-Type: text/html; charset=utf-8');
require_once '../inc/common.inc.php';
require_once '../inc/DirList.class.php';
define('APACHE_MIME_TYPES_URL', 'http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types');
function generateUpToDateMimeArray($url)
{
    $ROOT = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
    $iconPath = $ROOT . '/static/icons/32/';
    // thankfully taken core portions from Josh Sean in user comments on
    // http://www.php.net/manual/en/function.mime-content-type.php
    $s = array();
    foreach (@explode("\n", @file_get_contents($url)) as $x) {
        if (isset($x[0]) && $x[0] !== '#' && preg_match_all('#([^\\s]+)#', $x, $out) && isset($out[1]) && ($c = count($out[1])) > 1) {
            for ($i = 1; $i < $c; $i++) {
                // echo "ONE  ".$out[1][$i]."   TWO".$out[1][0]."<br/>";
                $ext = $out[1][$i];
                if (!isset(DirList::$mappings[$ext]) && !file_exists($iconPath . $ext . '.png')) {
                    continue;
                }
                $s[] = '&nbsp;&nbsp;&nbsp;\'' . $out[1][$i] . '\' => \'' . $out[1][0] . '\'';
            }
        }
    }
    return @sort($s) ? '$mime_types = array(<br />' . implode($s, ',<br />') . '<br />);' : false;
}
echo generateUpToDateMimeArray(APACHE_MIME_TYPES_URL);