Skip to content

Instantly share code, notes, and snippets.

@hayleyxyz
hayleyxyz / AsciiSafeDownloadFile.php
Created November 4, 2014 21:04
Laravel workaround for Symphony Download Response Error: "the filename fallback must only contain ASCII characters". Extend the Symfony\Component\HttpFoundation\File\File object to return an ASCII-safe value for getFilename()
<?php
use Symfony\Component\HttpFoundation\File\File;
/*
This class is a hack/workaround for the InvalidArgumentException "The filename fallback must only contain ASCII characters."
for file downloads with non-ASCII filenames. Since the Response::download() method doesn't allow specifying a fallback name,
this is the only realistic option, aside from extending, rewriting, and maintaining a bunch of framework classes, or
modifying the framework itself.
*/