deleteFileAfterSend example

try {
            $exportFilePath = $exporter->export($emotionId);
        } catch (Exception $e) {
            echo $e->getMessage();

            return;
        }

        @set_time_limit(0);

        $binaryResponse = new BinaryFileResponse($exportFilePath, 200, [], true, ResponseHeaderBag::DISPOSITION_ATTACHMENT);
        $binaryResponse->deleteFileAfterSend();
        $binaryResponse->send();

        exit;
    }

    /** * Uploads emotion zip archive to shopware file system * * @throws Exception * * @return void */
public function testDeleteFileAfterSend()
    {
        $request = Request::create('/');

        $path = __DIR__.'/File/Fixtures/to_delete';
        touch($path);
        $realPath = realpath($path);
        $this->assertFileExists($realPath);

        $response = new BinaryFileResponse($realPath, 200, ['Content-Type' => 'application/octet-stream']);
        $response->deleteFileAfterSend(true);

        $response->prepare($request);
        $response->sendContent();

        $this->assertFileDoesNotExist($path);
    }

    public function testAcceptRangeOnUnsafeMethods()
    {
        $request = Request::create('/', 'POST');
        $response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif', 200, ['Content-Type' => 'application/octet-stream']);
        
Home | Imprint | This part of the site doesn't use cookies.