class BinaryFileResponseTestController

Same name in other branches
  1. 11.x core/modules/system/tests/modules/binary_file_response_test/src/Controller/BinaryFileResponseTestController.php \Drupal\binary_file_response_test\Controller\BinaryFileResponseTestController

Controller routines for binary file response tests.

Hierarchy

Expanded class hierarchy of BinaryFileResponseTestController

File

core/modules/system/tests/modules/binary_file_response_test/src/Controller/BinaryFileResponseTestController.php, line 12

Namespace

Drupal\binary_file_response_test\Controller
View source
class BinaryFileResponseTestController {
    
    /**
     * Download the file set in the relative_file_url query parameter.
     *
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
     *   The response wrapping the file content.
     */
    public function download(Request $request) {
        if (!$request->query
            ->has('relative_file_url')) {
            throw new BadRequestHttpException();
        }
        $relative_file_url = $request->query
            ->get('relative_file_url');
        // A relative URL for a file contains '%20' instead of spaces. A relative
        // file path contains spaces.
        $relative_file_path = rawurldecode($relative_file_url);
        // Ensure the file path does not start with a slash to prevent exploring
        // the file system root.
        $relative_file_path = ltrim($relative_file_path, '/');
        return new BinaryFileResponse($relative_file_path);
    }

}

Members

Title Sort descending Modifiers Object type Summary
BinaryFileResponseTestController::download public function Download the file set in the relative_file_url query parameter.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.