Пример #1
0
        $allowedResources = array_merge($allowedResources, $config['allowed_resources']);
    }
}
// Serve file if it's materialized
$request = new \Magento\MediaStorage\Model\File\Storage\Request(__DIR__);
if ($mediaDirectory) {
    if (0 !== stripos($request->getPathInfo(), $mediaDirectory . '/') || is_dir($request->getFilePath())) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    $relativeFilename = str_replace($mediaDirectory . '/', '', $request->getPathInfo());
    if (!$isAllowed($relativeFilename, $allowedResources)) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    if (is_readable($request->getFilePath())) {
        $transfer = new \Magento\Framework\File\Transfer\Adapter\Http(new \Magento\Framework\HTTP\PhpEnvironment\Response(), new \Magento\Framework\File\Mime());
        $transfer->send($request->getFilePath());
        exit;
    }
}
// Materialize file in application
$params = $_SERVER;
if (empty($mediaDirectory)) {
    $params[ObjectManagerFactory::INIT_PARAM_DEPLOYMENT_CONFIG] = [];
    $params[Factory::PARAM_CACHE_FORCED_OPTIONS] = ['frontend_options' => ['disable_save' => true]];
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\MediaStorage\App\Media $app */
$app = $bootstrap->createApplication('Magento\\MediaStorage\\App\\Media', ['request' => $request, 'workingDirectory' => __DIR__, 'mediaDirectory' => $mediaDirectory, 'configCacheFile' => $configCacheFile, 'isAllowed' => $isAllowed, 'relativeFileName' => $relativeFilename]);
$bootstrap->run($app);
Пример #2
0
    if (filemtime($configCacheFile) + $config['update_time'] > time()) {
        $mediaDirectory = $config['media_directory'];
        $allowedResources = $config['allowed_resources'];
        // Serve file if it's materialized
        if ($mediaDirectory) {
            if (!$isAllowed($relativePath, $allowedResources)) {
                header('HTTP/1.0 404 Not Found');
                exit;
            }
            $mediaAbsPath = $mediaDirectory . '/' . $relativePath;
            if (is_readable($mediaAbsPath)) {
                if (is_dir($mediaAbsPath)) {
                    header('HTTP/1.0 404 Not Found');
                    exit;
                }
                $transfer = new \Magento\Framework\File\Transfer\Adapter\Http(new \Magento\Framework\HTTP\PhpEnvironment\Response(), new \Magento\Framework\File\Mime());
                $transfer->send($mediaAbsPath);
                exit;
            }
        }
    }
}
// Materialize file in application
$params = $_SERVER;
if (empty($mediaDirectory)) {
    $params[ObjectManagerFactory::INIT_PARAM_DEPLOYMENT_CONFIG] = [];
    $params[Factory::PARAM_CACHE_FORCED_OPTIONS] = ['frontend_options' => ['disable_save' => true]];
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\MediaStorage\App\Media $app */
$app = $bootstrap->createApplication('Magento\\MediaStorage\\App\\Media', ['mediaDirectory' => $mediaDirectory, 'configCacheFile' => $configCacheFile, 'isAllowed' => $isAllowed, 'relativeFileName' => $relativePath]);