{"id":14966445,"url":"https://github.com/yiisoft/response-download","last_synced_at":"2026-04-09T22:23:02.915Z","repository":{"uuid":"604163951","full_name":"yiisoft/response-download","owner":"yiisoft","description":"The package provides a factory to help forming file download PSR-7 response","archived":false,"fork":false,"pushed_at":"2024-02-14T07:56:35.000Z","size":40,"stargazers_count":9,"open_issues_count":2,"forks_count":3,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-04-13T23:13:21.955Z","etag":null,"topics":["download","file","http","psr-7","response","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2023-02-20T13:22:18.000Z","updated_at":"2023-12-21T14:24:05.000Z","dependencies_parsed_at":"2023-06-26T23:47:40.448Z","dependency_job_id":"998bcb77-0b3c-45eb-91b7-5e8645c7b040","html_url":"https://github.com/yiisoft/response-download","commit_stats":{"total_commits":17,"total_committers":5,"mean_commits":3.4,"dds":0.5294117647058824,"last_synced_commit":"263bb2ced6ec6c73c3e4434f835ced538f216822"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fresponse-download","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fresponse-download/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fresponse-download/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fresponse-download/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/response-download/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":199578804,"owners_count":13620455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["download","file","http","psr-7","response","yii3"],"created_at":"2024-09-24T13:36:23.801Z","updated_at":"2026-04-09T22:23:02.902Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii PSR-7 Download Response Factory\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/response-download/v/stable.png)](https://packagist.org/packages/yiisoft/response-download)\n[![Total Downloads](https://poser.pugx.org/yiisoft/response-download/downloads.png)](https://packagist.org/packages/yiisoft/response-download)\n[![Build status](https://github.com/yiisoft/response-download/workflows/build/badge.svg)](https://github.com/yiisoft/response-download/actions?query=workflow%3Abuild)\n[![Code Coverage](https://codecov.io/gh/yiisoft/response-download/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/response-download)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fresponse-download%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/response-download/master)\n[![static analysis](https://github.com/yiisoft/response-download/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/response-download/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/response-download/coverage.svg)](https://shepherd.dev/github/yiisoft/response-download)\n[![psalm-level](https://shepherd.dev/github/yiisoft/response-download/level.svg)](https://shepherd.dev/github/yiisoft/response-download)\n\nThe package provides a factory to help forming file download PSR-7 response.\n\n## Requirements\n\n- PHP 8.1 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/response-download\n```\n\n## General usage\n\nUse the factory to form a response:\n\n```php\nuse Psr\\Http\\Message\\ResponseInterface;\nuse Yiisoft\\ResponseDownload\\DownloadResponseFactory;\n\nfinal class MyController\n{\n    public function __construct(\n        private readonly DownloadResponseFactory $downloadResponseFactory,\n    )\n    {    \n    }\n\n    public function sendMyContentAsFile(): ResponseInterface\n    {\n        return $this-\u003edownloadResponseFactory-\u003esendContentAsFile('Hello!', 'message.txt');\n    }\n    \n    public function sendMyFile(): ResponseInterface\n    {\n        return $this-\u003edownloadResponseFactory-\u003esendFile('message.txt');\n    }\n    \n    public function xSendMyFile(): ResponseInterface\n    {\n        return $this-\u003edownloadResponseFactory-\u003exSendFile('message.txt');\n    }\n    \n    public function sendMyStreamAsFile(): ResponseInterface\n    {\n        $stream = new MyStream();\n        \n        return $this-\u003edownloadResponseFactory-\u003esendStreamAsFile($stream, 'message.txt');\n    }\n}\n```\n\nNote the `xSendFile()`. It is a special method that delegates the hard work to the web server instead of serving the\nfile using PHP.\n\n### X-Sendfile and Nginx\n\nDifferent web servers use different header names for the x-sendfile feature:\n\n| Web server | Header name |\n|---|---|\n| Apache | `X-Sendfile` (default) |\n| Lighttpd v1.4 | `X-LIGHTTPD-send-file` |\n| Lighttpd v1.5 | `X-Sendfile` |\n| Nginx | `X-Accel-Redirect` |\n| Cherokee | `X-Sendfile` or `X-Accel-Redirect` |\n| FrankenPHP | `X-Accel-Redirect` |\n\nWhen using **Nginx**, pass `'X-Accel-Redirect'` as the `$xHeader` argument. Nginx also requires an `internal`\nlocation block in its configuration that maps to the directory where your files are stored:\n\n```nginx\nlocation /protected/ {\n    internal;\n    alias /var/www/files/;\n}\n```\n\nThen call `xSendFile()` with the internal Nginx location path as the file path:\n\n```php\npublic function xSendMyFile(): ResponseInterface\n{\n    return $this-\u003edownloadResponseFactory-\u003exSendFile(\n        '/protected/myfile.txt',\n        xHeader: 'X-Accel-Redirect',\n    );\n}\n```\n\nThe `internal` directive ensures the location is only accessible internally by Nginx (not directly by clients),\nwhile `alias` maps the internal path to the real file system path.\n\nOptional arguments and defaults:\n\n- If attachment name is not specified in `sendFile()` or `xSendFile()`, it will be taken from the name of the file\nserved.\n- Each file sending method could also be provided with optional mime type and optional content disposition.\n- If mime type is omitted, for `sendContentAsFile()`, `sendFile()` and `xSendFile()` it will be determined based on\nthe file content. For other methods or when unable to determine the mime type, \"application/octet-stream\" will be used.\n- Content disposition is \"attachment\" by default. It will trigger browser's download dialog. If you want the content\nof the file to be displayed inline, set it to `Yiisoft\\Http\\ContentDispositionHeader\\ContentDispositionHeader::INLINE`.\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii PSR-7 Download Response Factory is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fresponse-download","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fresponse-download","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fresponse-download/lists"}