serverStaticFile() публичный статический Метод

It performs the following actions: - Checks the file is readable or returns "HTTP/1.0 404 Not Found" - Returns "HTTP/1.1 304 Not Modified" after comparing the HTTP_IF_MODIFIED_SINCE with the modification date of the static file - Will try to compress the static file according to HTTP_ACCEPT_ENCODING. Compressed files are store in the /tmp directory. If compressing extensions are not available, a manually gzip compressed file can be provided in the /tmp directory. It has to bear the same name with an added .gz extension. Using manually compressed static files requires you to manually update the compressed file when the static file is updated. - Overrides server cache control config to allow caching - Sends Very Accept-Encoding to tell proxies to store different version of the static file according to users encoding capacities. Warning: Compressed filed are stored in the /tmp directory. If this method is used with two files bearing the same name but located in different locations, there is a risk of conflict. One file could be served with the content of the other. A future upgrade of this method would be to recreate the directory structure of the static file within a /tmp/compressed-static-files directory.
public static serverStaticFile ( string $file, string $contentType, $expireFarFutureDays = 100, integer | false $byteStart = false, integer | false $byteEnd = false, string | false $filename = false )
$file string The location of the static file to serve
$contentType string The content type of the static file.
$byteStart integer | false The starting byte in the file to serve. If false, the data from the beginning of the file will be served.
$byteEnd integer | false The ending byte in the file to serve. If false, the data from $byteStart to the end of the file will be served.
$filename string | false By default the filename of $file is reused as Content-Disposition. If the file should be sent as a different filename to the client you can specify a custom filename here.
Пример #1
0
    exit;
}
/**
 * piwik.js proxy
 *
 * @see core/Piwik.php
 */
define('PIWIK_INCLUDE_PATH', '..');
define('PIWIK_DOCUMENT_ROOT', '..');
define('PIWIK_USER_PATH', '..');
require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
// Composer autoloader
if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) {
    $path = PIWIK_INCLUDE_PATH . '/vendor/autoload.php';
    // Piwik is the main project
} else {
    $path = PIWIK_INCLUDE_PATH . '/../../autoload.php';
    // Piwik is installed as a dependency
}
require $path;
$file = '../piwik.js';
$daysExpireFarFuture = 10;
$byteStart = $byteEnd = false;
if (!defined("PIWIK_KEEP_JS_TRACKER_COMMENT") || !PIWIK_KEEP_JS_TRACKER_COMMENT) {
    $byteStart = 369;
    // length of comment header in bytes
}
$environment = new \Piwik\Application\Environment(null);
$environment->init();
ProxyHttp::serverStaticFile($file, "application/javascript; charset=UTF-8", $daysExpireFarFuture, $byteStart, $byteEnd);
exit;
Пример #2
0
 /**
  * @param UIAsset $uiAsset
  */
 private function serveJsFile($uiAsset)
 {
     ProxyHttp::serverStaticFile($uiAsset->getAbsoluteLocation(), self::JS_MIME_TYPE);
 }
Пример #3
0
 * the execution of Piwik:serverStaticFile(). In this case, unit tests won't be executed
 */
// Getting the server mode
$staticFileServerMode = Common::getRequestVar(SRV_MODE_REQUEST_VAR, "");
// Setting zlib output compression as requested
ini_set('zlib.output_compression', Common::getRequestVar(ZLIB_OUTPUT_REQUEST_VAR, '0'));
if ($staticFileServerMode === "") {
    throw new Exception("When this testing file is used as a static file server, the request parameter " . SRV_MODE_REQUEST_VAR . " must be provided.");
}
switch ($staticFileServerMode) {
    // The static file server calls Piwik::serverStaticFile with a null file
    case NULL_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(null, TEST_FILE_CONTENT_TYPE);
        break;
        // The static file server calls Piwik::serverStaticFile with a non-existing file
    // The static file server calls Piwik::serverStaticFile with a non-existing file
    case GHOST_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE);
        break;
        // The static file server calls Piwik::serverStaticFile with the test file
    // The static file server calls Piwik::serverStaticFile with the test file
    case TEST_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE);
        break;
    case PARTIAL_TEST_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE, $expireFarFutureDays = 100, PARTIAL_BYTE_START, PARTIAL_BYTE_END);
        break;
    case WHOLE_TEST_FILE_WITH_RANGE_SRV_MODE:
        ProxyHttp::serverStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE, $expireFarFutureDays = 100, 0, filesize(TEST_FILE_LOCATION));
        break;
}
Пример #4
0
<?php

/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
use Piwik\ProxyHttp;
/**
 * Tracker proxy
 */
if ($_SERVER['REQUEST_METHOD'] == 'POST' || !empty($_SERVER['QUERY_STRING'])) {
    include '../piwik.php';
    exit;
}
/**
 * piwik.js proxy
 *
 * @see core/Piwik.php
 */
define('PIWIK_INCLUDE_PATH', '..');
define('PIWIK_DOCUMENT_ROOT', '..');
define('PIWIK_USER_PATH', '..');
require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
$file = '../piwik.js';
// There is no cache buster parameter so we don't set Expires: header
$expireFarFuture = false;
ProxyHttp::serverStaticFile($file, "application/javascript; charset=UTF-8", $expireFarFuture);
exit;
Пример #5
0
 public function download()
 {
     Piwik::checkUserHasSuperUserAccess();
     $this->dieIfPluginsAdminIsDisabled();
     $pluginName = new PluginName();
     $pluginName = $pluginName->getPluginName();
     Nonce::checkNonce($pluginName);
     $filename = $pluginName . '.zip';
     try {
         $pathToPlugin = $this->marketplaceApi->download($pluginName);
         ProxyHttp::serverStaticFile($pathToPlugin, 'application/zip', $expire = 0, $start = false, $end = false, $filename);
     } catch (Exception $e) {
         Common::sendResponseCode(500);
         Log::warning('Could not download file . ' . $e->getMessage());
     }
     if (!empty($pathToPlugin)) {
         Filesystem::deleteFileIfExists($pathToPlugin);
     }
 }
Пример #6
0
// These constants define which action will be performed by the static server.
define("NULL_FILE_SRV_MODE", "nullFile");
define("GHOST_FILE_SRV_MODE", "ghostFile");
define("TEST_FILE_SRV_MODE", "testFile");
/**
 * If the static file server has been requested, the response sent back to the browser will be the content produced by
 * the execution of Piwik:serverStaticFile(). In this case, unit tests won't be executed
 */
// Getting the server mode
$staticFileServerMode = Common::getRequestVar(SRV_MODE_REQUEST_VAR, "");
// Setting zlib output compression as requested
ini_set('zlib.output_compression', Common::getRequestVar(ZLIB_OUTPUT_REQUEST_VAR, '0'));
if ($staticFileServerMode === "") {
    throw new Exception("When this testing file is used as a static file server, the request parameter " . SRV_MODE_REQUEST_VAR . " must be provided.");
}
switch ($staticFileServerMode) {
    // The static file server calls Piwik::serverStaticFile with a null file
    case NULL_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(null, TEST_FILE_CONTENT_TYPE);
        break;
        // The static file server calls Piwik::serverStaticFile with a non-existing file
    // The static file server calls Piwik::serverStaticFile with a non-existing file
    case GHOST_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE);
        break;
        // The static file server calls Piwik::serverStaticFile with the test file
    // The static file server calls Piwik::serverStaticFile with the test file
    case TEST_FILE_SRV_MODE:
        ProxyHttp::serverStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE);
        break;
}