Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

suntrop's avatar

response()->download() with UTF8 filenames

Hi! I am just digging into Laravel and need some help with response()->download()

When I try to send a file as download I get an error the file doesn't exists. But when I change its name from "special-characers-ö-test.txt" to "special-characers-x-test.txt" and send this file everything works fine.

I can't believe L5 is only capable to handel ASCII filenames – especially because Symfony's HTTPFoundation handles them correctly https://github.com/symfony/symfony/issues/8647

Anybody knows a workaround?

(Files are synced from another server, I can't change them before)

0 likes
2 replies
flo's avatar

@suntrop have you found a solution yet? I'm running into the same issue.

adamhut's avatar

try the following, it works for me.

         $filename = urlencode($filename);

    
    $content = Storage::get($this->fileFolder.$realname);
    $response = response($content)
        ->withHeaders([
            'Content-type' => 'application/force-download',
            'Content-Transfer-Encoding' => 'Binary',
            'Content-Disposition' => 'attachment;filename='.$filename,
        ]);
    return $response;

Please or to participate in this conversation.