Ejemplo n.º 1
0
    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;
}
header('Content-Type: ' . $file->mime());
header('Content-Length: ' . $file->size());
readfile($file->path());
Ejemplo n.º 2
0
    $out = shell(sprintf('locate %s', escapeshellarg(trim($_GET['q']))));
    $fields = array(new TableFieldIcon(), new TableFieldLink('Name', 'path', 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('Permissions', 'perms'));
    $rows = array();
    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'], '/')));