Ejemplo n.º 1
0
/**
* Check if the browser has the file already and set the appropriate headers-
* @returns false if a resend is in order.
*/
function set_modified_headers($stamp, $browser)
{
    global $request;
    // let's see if we have to send the file at all
    $last_load = $request->header('Modified-Since') ? strtotime(trim($request->header('Modified-Since'))) : false;
    if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie_version($browser, 7)) {
        if ($last_load !== false && $last_load >= $stamp) {
            send_status_line(304, 'Not Modified');
            // seems that we need those too ... browsers
            header('Cache-Control: public');
            header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
            return true;
        } else {
            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $stamp) . ' GMT');
        }
    }
    return false;
}
Ejemplo n.º 2
0
 $display_cat = $extensions[$attachment['extension']]['display_cat'];
 if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg')) {
     $display_cat = ATTACHMENT_CATEGORY_NONE;
 }
 if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash')) {
     $display_cat = ATTACHMENT_CATEGORY_NONE;
 }
 if ($thumbnail) {
     $attachment['physical_filename'] = 'thumb_' . $attachment['physical_filename'];
 } else {
     if ($display_cat == ATTACHMENT_CATEGORY_NONE && !$attachment['is_orphan'] && !phpbb_http_byte_range($attachment['filesize'])) {
         // Update download count
         phpbb_increment_downloads($db, $attachment['attach_id']);
     }
 }
 if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && strpos($attachment['mimetype'], 'image') === 0 && strpos(strtolower($user->browser), 'msie') !== false && !phpbb_is_greater_ie_version($user->browser, 7)) {
     wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']);
     file_gc();
 } else {
     // Determine the 'presenting'-method
     if ($download_mode == PHYSICAL_LINK) {
         // This presenting method should no longer be used
         if (!@is_dir($phpbb_root_path . $config['upload_path'])) {
             send_status_line(500, 'Internal Server Error');
             trigger_error($user->lang['PHYSICAL_DOWNLOAD_NOT_POSSIBLE']);
         }
         redirect($phpbb_root_path . $config['upload_path'] . '/' . $attachment['physical_filename']);
         file_gc();
     } else {
         send_file_to_browser($attachment, $config['upload_path'], $display_cat);
         file_gc();
Ejemplo n.º 3
0
 /**
  * @dataProvider user_agents_check_greater_ie_version
  */
 public function test_is_greater_ie_version($user_agent, $version, $expected)
 {
     $this->assertEquals($expected, phpbb_is_greater_ie_version($user_agent, $version));
 }
Ejemplo n.º 4
0
/**
* Check if the browser has the file already and set the appropriate headers-
* @returns false if a resend is in order.
*/
function set_modified_headers($stamp, $browser)
{
    // let's see if we have to send the file at all
    $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false;
    if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie_version($browser, 7)) {
        if ($last_load !== false && $last_load >= $stamp) {
            send_status_line(304, 'Not Modified');
            // seems that we need those too ... browsers
            header('Pragma: public');
            header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 31536000));
            return true;
        } else {
            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $stamp) . ' GMT');
        }
    }
    return false;
}
Ejemplo n.º 5
-1
    /**
     * Send file to browser
     *
     * Copy of send_file_to_browser() from functions_download.php
     * with some minor modifications to work correctly in Titania.
     *
     * @param array $attachment	Attachment data.
     * @param string $filename	Full path to the attachment file.
     * @param int $category		Attachment category.
     *
     * @return \Symfony\Component\HttpFoundation\Response if error found. Otherwise method exits.
     */
    protected function send_file_to_browser($attachment, $filename, $category)
    {
        if (!@file_exists($filename)) {
            return $this->helper->error('ERROR_NO_ATTACHMENT', 404);
        }
        // Correct the mime type - we force application/octetstream for all files, except images
        // Please do not change this, it is a security precaution
        if ($category != ATTACHMENT_CATEGORY_IMAGE || strpos($attachment['mimetype'], 'image') !== 0) {
            $attachment['mimetype'] = strpos(strtolower($this->user->browser), 'msie') !== false || strpos(strtolower($this->user->browser), 'opera') !== false ? 'application/octetstream' : 'application/octet-stream';
        }
        if (@ob_get_length()) {
            @ob_end_clean();
        }
        // Now send the File Contents to the Browser
        $size = @filesize($filename);
        // To correctly display further errors we need to make sure we are using the correct headers for both (unsetting content-length may not work)
        // Check if headers already sent or not able to get the file contents.
        if (headers_sent() || !@file_exists($filename) || !@is_readable($filename)) {
            // PHP track_errors setting On?
            if (!empty($php_errormsg)) {
                return $this->helper->error($this->user->lang['UNABLE_TO_DELIVER_FILE'] . '<br />' . $this->user->lang('TRACKED_PHP_ERROR', $php_errormsg), self::INTERNAL_SERVER_ERROR);
            }
            return $this->helper->error('UNABLE_TO_DELIVER_FILE', self::INTERNAL_SERVER_ERROR);
        }
        // Make sure the database record for the filesize is correct
        if ($size > 0 && $size != $attachment['filesize']) {
            // Update database record
            $sql = 'UPDATE ' . TITANIA_ATTACHMENTS_TABLE . '
				SET filesize = ' . (int) $size . '
				WHERE attachment_id = ' . (int) $attachment['attachment_id'];
            $this->db->sql_query($sql);
        }
        // Now the tricky part... let's dance
        header('Pragma: public');
        // Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer.
        header('Content-Type: ' . $attachment['mimetype']);
        if (phpbb_is_greater_ie_version($this->user->browser, 7)) {
            header('X-Content-Type-Options: nosniff');
        }
        if ($category == ATTACHMENT_CATEGORY_FLASH && request_var('view', 0) === 1) {
            // We use content-disposition: inline for flash files and view=1 to let it correctly play with flash player 10 - any other disposition will fail to play inline
            header('Content-Disposition: inline');
        } else {
            if (empty($this->user->browser) || strpos(strtolower($this->user->browser), 'msie') !== false && !phpbb_is_greater_ie_version($this->user->browser, 7)) {
                header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
                if (empty($this->user->browser) || strpos(strtolower($this->user->browser), 'msie 6.0') !== false) {
                    header('expires: -1');
                }
            } else {
                header('Content-Disposition: ' . (strpos($attachment['mimetype'], 'image') === 0 ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename'])));
                if (phpbb_is_greater_ie_version($this->user->browser, 7) && strpos($attachment['mimetype'], 'image') !== 0) {
                    header('X-Download-Options: noopen');
                }
            }
        }
        if ($size) {
            header("Content-Length: {$size}");
        }
        // Close the db connection before sending the file etc.
        file_gc(false);
        if (!set_modified_headers($attachment['filetime'], $this->user->browser)) {
            // Try to deliver in chunks
            @set_time_limit(0);
            $fp = @fopen($filename, 'rb');
            if ($fp !== false) {
                // Deliver file partially if requested
                if ($range = phpbb_http_byte_range($size)) {
                    fseek($fp, $range['byte_pos_start']);
                    send_status_line(206, 'Partial Content');
                    header('Content-Range: bytes ' . $range['byte_pos_start'] . '-' . $range['byte_pos_end'] . '/' . $range['bytes_total']);
                    header('Content-Length: ' . $range['bytes_requested']);
                }
                while (!feof($fp)) {
                    echo fread($fp, 8192);
                }
                fclose($fp);
            } else {
                @readfile($filename);
            }
            flush();
        }
        exit;
    }