Пример #1
0
    foreach (explode("\n", $out) as $row) {
        if (!empty($row)) {
            $rows[] = new TableRow(new FileModel($row), $fields);
        }
    }
    $middle = render_str('foobar/table', compact('fields', 'rows'));
} else {
    $file = new FileModel($f);
    if (is_dir($f)) {
        $fields = array(new TableFieldIcon(), new TableFieldLink('Name', 'basename', function (FileModel $file) {
            return url(array('q' => false, 'f' => $file->path()));
        }), new TableField('Type', 'type'), new TableFieldFormat('Size', 'size', 'format_bytes'), new TableField('MIME', 'mime'), new TableField('Owner', 'owner'), new TableField('Group', 'group'), new TableField('Permissions', 'perms'));
        $rows = $file->rows();
        $middle = render_str('foobar/table', array('fields' => $fields, 'rows' => new TableRowGenerator($rows, $fields)));
    } else {
        switch ($file->mime()) {
            case 'audio/mpeg':
                if (begins($file->realpath(), $_SERVER['DOCUMENT_ROOT'])) {
                    $middle = render_str('foobar/audio', array('src' => replace_prefix($file->realpath(), $_SERVER['DOCUMENT_ROOT'], '/')));
                } else {
                    $middle = render_str('foobar/audio', array('src' => 'image.php?' . http_build_query(array('f' => $file->realpath()))));
                }
                break;
            case 'video/mp4':
                if (begins($file->realpath(), $_SERVER['DOCUMENT_ROOT'])) {
                    $middle = render_str('foobar/video', array('src' => replace_prefix($file->realpath(), $_SERVER['DOCUMENT_ROOT'], '/')));
                } else {
                    $middle = render_str('foobar/video', array('src' => 'image.php?' . http_build_query(array('f' => $file->realpath()))));
                }
                break;
            case 'image/svg+xml':
Пример #2
0
<?php

require __DIR__ . '/../share/app.php';
if (empty($_GET['f'])) {
    header('HTTP/1.1 404 Not Found');
    render('page/404');
    exit;
}
$f = $_GET['f'];
if (!file_exists($f)) {
    header('HTTP/1.1 404 Not Found');
    render('page/404');
    exit;
}
$file = new FileModel($_GET['f']);
switch ($file->mime()) {
    case 'video/mp4':
    case 'image/svg+xml':
    case 'image/png':
    case 'image/jpeg':
    case 'image/gif':
        $image = true;
        break;
    default:
        $image = false;
        break;
}
if (!$image || !is_readable($f)) {
    header('HTTP/1.1 403 Permission denied');
    render('page/403', array('message' => 'Permission denied'));
    exit;
Пример #3
0
function format_file_glyphicon(FileModel $file)
{
    if ($file->type() == 'dir') {
        return 'glyphicon glyphicon-folder-close';
    }
    switch ($file->mime()) {
        case 'image/gif':
        case 'image/jpeg':
        case 'image/png':
        case 'image/svg+xml':
        case 'image/tiff':
        case 'image/vnd.microsoft.icon':
        case 'image/x-ms-bmp':
            return 'glyphicon glyphicon-picture';
        case 'video/3gpp':
        case 'video/annodex':
        case 'video/dl':
        case 'video/dv':
        case 'video/fli':
        case 'video/gl':
        case 'video/mpeg':
        case 'video/MP2T':
        case 'video/mp4':
        case 'video/quicktime':
        case 'video/mp4v-es':
        case 'video/ogg':
        case 'video/parityfec':
        case 'video/pointer':
        case 'video/webm':
        case 'video/vnd.fvt':
        case 'video/vnd.motorola.video':
        case 'video/vnd.motorola.videop':
        case 'video/vnd.mpegurl':
        case 'video/vnd.mts':
        case 'video/vnd.nokia.interleaved-multimedia':
        case 'video/vnd.vivo':
        case 'video/x-flv':
        case 'video/x-la-asf':
        case 'video/x-mng':
        case 'video/x-ms-asf':
        case 'video/x-ms-wm':
        case 'video/x-ms-wmv':
        case 'video/x-ms-wmx':
        case 'video/x-ms-wvx':
        case 'video/x-msvideo':
        case 'video/x-sgi-movie':
        case 'video/x-matroska':
            return 'glyphicon glyphicon-film';
        case 'audio/32kadpcm':
        case 'audio/3gpp':
        case 'audio/amr':
        case 'audio/amr-wb':
        case 'audio/annodex':
        case 'audio/basic':
        case 'audio/csound':
        case 'audio/flac':
        case 'audio/g.722.1':
        case 'audio/l16':
        case 'audio/midi':
        case 'audio/mp4a-latm':
        case 'audio/mpa-robust':
        case 'audio/mpeg':
        case 'audio/mpegurl':
        case 'audio/ogg':
        case 'audio/parityfec':
        case 'audio/prs.sid':
        case 'audio/telephone-event':
        case 'audio/tone':
        case 'audio/vnd.cisco.nse':
        case 'audio/vnd.cns.anp1':
        case 'audio/vnd.cns.inf1':
        case 'audio/vnd.digital-winds':
        case 'audio/vnd.everad.plj':
        case 'audio/vnd.lucent.voice':
        case 'audio/vnd.nortel.vbk':
        case 'audio/vnd.nuera.ecelp4800':
        case 'audio/vnd.nuera.ecelp7470':
        case 'audio/vnd.nuera.ecelp9600':
        case 'audio/vnd.octel.sbc':
        case 'audio/vnd.qcelp':
        case 'audio/vnd.rhetorex.32kadpcm':
        case 'audio/vnd.vmx.cvsd':
        case 'audio/x-aiff':
        case 'audio/x-gsm':
        case 'audio/x-mpegurl':
        case 'audio/x-ms-wma':
        case 'audio/x-ms-wax':
        case 'audio/x-pn-realaudio-plugin':
        case 'audio/x-pn-realaudio':
        case 'audio/x-realaudio':
        case 'audio/x-scpls':
        case 'audio/x-sd2':
        case 'audio/x-wav':
            return 'glyphicon glyphicon-music';
        default:
            return 'glyphicon glyphicon-file';
    }
}