getSize() public method

Return the size of the file in bytes.
Since: 1.9
public getSize ( ) : integer
return integer
Exemplo n.º 1
0
 /**
  * @group FileService
  */
 public function testCanTellPosition()
 {
     $size = $this->file->getSize();
     $this->assertNotEmpty($size);
     $this->assertNotEmpty($this->file->open('read'));
     $this->assertEquals(0, $this->file->seek(2));
     $this->assertEquals(2, $this->file->tell());
     $this->assertFalse($this->file->eof());
     $this->assertEquals(0, $this->file->seek($size));
     $this->assertFalse($this->file->eof());
     $this->file->read(1);
     $this->assertTrue($this->file->eof());
     $this->assertTrue($this->file->close());
 }
Exemplo n.º 2
0
Arquivo: view.php Projeto: ibou77/elgg
}
// If user doesn't exist, return default icon
if (!$user) {
    $url = "_graphics/icons/default/{$size}.png";
    $url = elgg_normalize_url($url);
    forward($url);
}
$user_guid = $user->getGUID();
// Try and get the icon
$filehandler = new ElggFile();
$filehandler->owner_guid = $user_guid;
$filehandler->setFilename("profile/{$user_guid}{$size}.jpg");
$success = false;
try {
    if ($filehandler->open("read")) {
        if ($contents = $filehandler->read($filehandler->getSize())) {
            $success = true;
        }
    }
} catch (InvalidParameterException $e) {
    elgg_log("Unable to get avatar for user with GUID {$user_guid}", 'ERROR');
}
if (!$success) {
    $url = "_graphics/icons/default/{$size}.png";
    $url = elgg_normalize_url($url);
    forward($url);
}
header("Content-type: image/jpeg", true);
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true);
header("Pragma: public", true);
header("Cache-Control: public", true);
Exemplo n.º 3
0
/**
 * @param $guid
 * @param $size
 * @throws IOException
 * @throws InvalidParameterException
 */
function group_get_icon($guid, $size)
{
    /* @var ElggGroup $group */
    $group = get_entity($guid);
    if (!$group instanceof ElggGroup) {
        header("HTTP/1.1 404 Not Found");
        exit;
    }
    // If is the same ETag, content didn't changed.
    $etag = $group->icontime . $guid;
    if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") {
        header("HTTP/1.1 304 Not Modified");
        exit;
    }
    if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar'))) {
        $size = "medium";
    }
    $success = false;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;
    $filehandler->setFilename("groups/" . $group->guid . $size . ".jpg");
    $success = false;
    if ($filehandler->open("read")) {
        if ($contents = $filehandler->read($filehandler->getSize())) {
            $success = true;
        }
    }
    header("Content-type: image/jpeg");
    header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+10 days")), true);
    header("Pragma: public", true);
    header("Cache-Control: public", true);
    header("Content-Length: " . strlen($contents));
    header("ETag: \"{$etag}\"");
    echo $contents;
    exit;
}
Exemplo n.º 4
0
/**
 * Handles browser pages
 *
 * @param array $segments An array of URL segments
 * @return boolean
 */
function ckeditor_addons_page_handler($segments)
{
    if (!elgg_get_plugin_setting('allow_uploads', 'ckeditor_addons')) {
        return false;
    }
    switch ($segments[0]) {
        case 'browse':
            echo elgg_view_resource('ckeditor/browse');
            return true;
        case 'image':
            $user_guid = $segments[1];
            $hash = $segments[2];
            $ext = $segments[3];
            if (!$user_guid || !$hash) {
                header("HTTP/1.1 400 Bad Request");
                exit;
            }
            if (!in_array($ext, array('jpg', 'gif'))) {
                $ext = 'jpg';
            }
            if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$hash}\"") {
                header("HTTP/1.1 304 Not Modified");
                exit;
            }
            $file = new ElggFile();
            $file->owner_guid = $user_guid;
            $file->setFilename("ckeditor/{$hash}.{$ext}");
            if (!$file->exists()) {
                header("HTTP/1.1 404 Not Found");
                exit;
            }
            $file->open('read');
            $contents = $file->grabFile();
            $file->close();
            if (md5($contents) != $hash) {
                header("HTTP/1.1 403 Forbidden");
                exit;
            }
            header("Content-type: image/jpeg");
            header("Etag: {$hash}");
            header('Expires: ' . date('r', time() + 864000));
            header("Pragma: public");
            header("Cache-Control: public");
            header("Content-Length: " . $file->getSize());
            ob_get_clean();
            echo $contents;
            exit;
        case 'assets':
            array_unshift($segments, 'ckeditor');
            $view = implode('/', $segments);
            forward(elgg_get_simplecache_url($view));
            break;
    }
    return false;
}