PHPackages                             cardinalby/content-disposition - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cardinalby/content-disposition

ActiveLibrary

cardinalby/content-disposition
==============================

1.1.1(2y ago)6352.7k—5.6%3MITPHPPHP &gt;=5.6

Since Jun 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/cardinalby/phpContentDisposition)[ Packagist](https://packagist.org/packages/cardinalby/content-disposition)[ RSS](/packages/cardinalby-content-disposition/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (3)

[![Test Suite](https://github.com/cardinalby/phpContentDisposition/actions/workflows/test.yml/badge.svg)](https://github.com/cardinalby/phpContentDisposition/actions/workflows/test.yml)[![Latest Stable Version](https://camo.githubusercontent.com/8b28c3a327ff5f2f026845fd458993475269e92123938f14f8320d9edccd09e4/687474703a2f2f706f7365722e707567782e6f72672f63617264696e616c62792f636f6e74656e742d646973706f736974696f6e2f76)](https://packagist.org/packages/cardinalby/content-disposition)[![Total Downloads](https://camo.githubusercontent.com/345cd6e4b446eafe3c6736a3457d338372094144e3621f92ba2abee9758e65e0/687474703a2f2f706f7365722e707567782e6f72672f63617264696e616c62792f636f6e74656e742d646973706f736974696f6e2f646f776e6c6f616473)](https://packagist.org/packages/cardinalby/content-disposition)[![Latest Unstable Version](https://camo.githubusercontent.com/6891cbd014fe23deccda6ac04429360279dee51ac6f5db56428a49323af37dfe/687474703a2f2f706f7365722e707567782e6f72672f63617264696e616c62792f636f6e74656e742d646973706f736974696f6e2f762f756e737461626c65)](https://packagist.org/packages/cardinalby/content-disposition)[![License](https://camo.githubusercontent.com/ee55cef013efc85693d007beda44598359215b3a2c8bd5d92d4973c8c84e6aec/687474703a2f2f706f7365722e707567782e6f72672f63617264696e616c62792f636f6e74656e742d646973706f736974696f6e2f6c6963656e7365)](https://packagist.org/packages/cardinalby/content-disposition)[![PHP Version Require](https://camo.githubusercontent.com/43298d27678c08d67e15f86f76e041bee569932d8859504c5e9e2a872f3447a2/687474703a2f2f706f7365722e707567782e6f72672f63617264696e616c62792f636f6e74656e742d646973706f736974696f6e2f726571756972652f706870)](https://packagist.org/packages/cardinalby/content-disposition)

PHP class for handling (parsing and formatting) a value of HTTP [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) header.

Requires **PHP 5.6** or newer.

Installation
------------

[](#installation)

```
composer require cardinalby/content-disposition
```

Content-Disposition header
--------------------------

[](#content-disposition-header)

The text value of the header is in ISO-8859-1 charset. The header contains:

- `Type`. Can be `attachment`, `inline` or custom.
- `filename` parameter that contains ISO-8859-1 compatible file name.
- `filename*` parameter that contains a file name in a custom charset (with charset specified and URL-encoded)

API
---

[](#api)

```
use cardinalby\ContentDisposition\ContentDisposition;
```

### 🔻 static `create(...)`

[](#-static-create)

```
public static function create(
    $fileName = null,
    $fallback = true,
    $type = 'attachment'
)
```

#### 🔸 `$fileName`

[](#-filename)

File name, can contain Unicode symbols. Depending on the symbols present in the string, value will be placed to `filename` or `filename*` param.

Pass `null` to omit `filename` param.

#### 🔸 `$fallback`

[](#-fallback)

If the `$filename` argument is outside ISO-8859-1, then the file name is actually stored in a supplemental `filename*` field for clients that support Unicode file names and a ISO-8859-1 version of the file name is automatically generated.

This specifies the ISO-8859-1 file name to override the automatic generation or disables the generation at all.

- `true` (*default*) will enable automatic generation if the file name is outside ISO-8859-1. Replaces non-ISO-8859-1 characters with '?' character.
- A **string** will specify the ISO-8859-1 file name to use in place of automatic generation. If it differs from `$filename`, then `$filename` option is encoded in the extended field and `$fallback` set as the fallback field, even though they are both ISO-8859-1
- `false` will disable including a ISO-8859-1 file name and only include the Unicode version (unless the file name is already ISO-8859-1).
- `null` will strictly disable including a ISO-8859-1 file name and only include the Unicode version even if file name is already ISO-8859-1.

#### 🔸 `$type`

[](#-type)

Specifies the disposition type, defaults to `"attachment"`. This can also be `"inline"`, or any other value (all values except inline are treated like `attachment`, but can convey additional information if both parties agree to it). The type is normalized to lower-case.

### 🔻 static `createAttachment(...)`

[](#-static-createattachment)

A shortcut for `ContentDisposition::create($filename, $fallback, 'attachment')`;

### 🔻 static `createInline(...)`

[](#-static-createinline)

A shortcut for `ContentDisposition::create($filename, $fallback, 'inline')`;

### 🔻 `format()`

[](#-format)

Generates the header string value (without header name).

```
$v = ContentDisposition::create('£ and € rates.pdf')->format();
// 'attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf'
```

### 🔻 `formatHeaderLine()`

[](#-formatheaderline)

Generates the full header line: `Content-Disposition: ...`, where `...` equals `format()` result.

### 🔻 static `parse()`

[](#-static-parse)

Parses a `Content-Disposition` header string and returns `ContentDisposition` object.

```
$cd = ContentDisposition::parse('attachment; filename="plans.pdf"');
assert($cd->getType() === 'attachment');
assert($cd->getFilename() === 'plans.pdf');
assert($cd->getParameters() === ['filename' => 'plans.pdf']);
```

```
$cd = ContentDisposition::parse(
    'attachment; filename="EURO rates.pdf"; filename*=UTF-8\'\'%E2%82%AC%20rates.pdf'
    );
assert($cd->getType() === 'attachment');
// Unicode version is preferable
assert($cd->getFilename() === '€ rates.pdf');
assert($cd->getParameters() === [
    'filename' => 'EURO rates.pdf',
    'filename*' => '€ rates.pdf'
]);
```

### 🔻 `getType()`

[](#-gettype)

Returns the download type

### 🔻 `getFilename()`

[](#-getfilename)

Returns a value of `filename*` param or (if doesn't exist) a value of `filename` param or `null` (if none exists).

### 🔻 `getParameters()`

[](#-getparameters)

Get associative array of all parameters including `filename` and `filename*`.

### 🔻 `getCustomParameters()`

[](#-getcustomparameters)

Get associative array of unknown parameters (except `filename` and `filename*`).

References
----------

[](#references)

Reference implementation: [content-disposition](https://github.com/jshttp/content-disposition) library for NodeJS.

- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1](https://tools.ietf.org/html/rfc2616)
- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters](https://tools.ietf.org/html/rfc5987)
- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)](https://tools.ietf.org/html/rfc6266)
- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987](http://greenbytes.de/tech/tc2231/)

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~174 days

Total

3

Last Release

1091d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bbfe0bf798727f19bd3047d7772f089946eb5f21a44bfa7788bb00b3c684a771?d=identicon)[cardinalby](/maintainers/cardinalby)

---

Top Contributors

[![cardinalby](https://avatars.githubusercontent.com/u/2001539?v=4)](https://github.com/cardinalby "cardinalby (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cardinalby-content-disposition/health.svg)

```
[![Health](https://phpackages.com/badges/cardinalby-content-disposition/health.svg)](https://phpackages.com/packages/cardinalby-content-disposition)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
