function HeaderUtils::makeDisposition
Generates an HTTP Content-Disposition field-value.
Parameters
string $disposition One of "inline" or "attachment":
string $filename A unicode string:
string $filenameFallback A string containing only ASCII characters that: is semantically equivalent to $filename. If the filename is already ASCII, it can be omitted, or just copied from $filename
Throws
\InvalidArgumentException
See also
RFC 6266
1 call to HeaderUtils::makeDisposition()
- ResponseHeaderBag::makeDisposition in vendor/
symfony/ http-foundation/ ResponseHeaderBag.php
File
-
vendor/
symfony/ http-foundation/ HeaderUtils.php, line 165
Class
- HeaderUtils
- HTTP header utility functions.
Namespace
Symfony\Component\HttpFoundationCode
public static function makeDisposition(string $disposition, string $filename, string $filenameFallback = '') : string {
if (!\in_array($disposition, [
self::DISPOSITION_ATTACHMENT,
self::DISPOSITION_INLINE,
])) {
throw new \InvalidArgumentException(\sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
}
if ('' === $filenameFallback) {
$filenameFallback = $filename;
}
// filenameFallback is not ASCII.
if (!preg_match('/^[\\x20-\\x7e]*$/', $filenameFallback)) {
throw new \InvalidArgumentException('The filename fallback must only contain ASCII characters.');
}
// percent characters aren't safe in fallback.
if (str_contains($filenameFallback, '%')) {
throw new \InvalidArgumentException('The filename fallback cannot contain the "%" character.');
}
// path separators aren't allowed in either.
if (str_contains($filename, '/') || str_contains($filename, '\\') || str_contains($filenameFallback, '/') || str_contains($filenameFallback, '\\')) {
throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
}
$params = [
'filename' => $filenameFallback,
];
if ($filename !== $filenameFallback) {
$params['filename*'] = "utf-8''" . rawurlencode($filename);
}
return $disposition . '; ' . self::toString($params, ';');
}