Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloads are broken because of semicolon appended to filename #13919

Closed
bbasinski opened this issue Mar 29, 2019 · 2 comments
Closed

Downloads are broken because of semicolon appended to filename #13919

bbasinski opened this issue Mar 29, 2019 · 2 comments
Labels
bug A bug report status: medium Medium

Comments

@bbasinski
Copy link

bbasinski commented Mar 29, 2019

Changes from #13496 breaks our all downloads. Downloaded file has semicolon appended to the extension which disable file type recognition by system (which is important). Tested both linux and windows, chrome and firefox. Even RFC 6266 Content-Disposition in HTTP omits semicolon at the end of header. Browser does not strip this. Tried to wrap filename in double quotes but with no luck. Only solution is to overwrite Content-Disposition header to remove semicolon from the end.

$this->response->setFileToSend($fileDir, $filename);

//fix
$this->response->setHeader("Content-Disposition", "attachment; filename=$filename");

Details

  • Phalcon version: 3.4.2
  • PHP Version: 7.2.15
  • Operating System: Debian
  • Server: Apache
@niden niden added 4.0 and removed 4.1 labels Jun 21, 2019
@StudioMaX
Copy link
Contributor

I always hated the Content-Disposition header. The current implementation in Phalcon is suitable for the simplest cases - when the filename is without any encodings and spaces, like filename.txt. For more complex file names each browser will react differently. Just look at this Test case: http://test.greenbytes.de/tech/tc2231/
Personally I use something like this:

if ($browserInfo['browser_name'] === 'Internet Explorer' && ($browserInfo['browser_version'] === '7.0' || $browserInfo['browser_version'] == '8.0')) {
    $filename = mb_convert_encoding($filename, 'UTF-8', 'Windows-1251');
    $contentDisposition = 'attachment; filename="' . rawurlencode($filename) . '"';
} elseif ($browserInfo['browser_name'] === 'Safari') {
    $filename = mb_convert_encoding($filename, 'UTF-8', 'Windows-1251');
    $contentDisposition = 'attachment; filename="' . $filename . '"';
} else {
    $filename = mb_convert_encoding($filename, 'UTF-8', 'Windows-1251');
    $contentDisposition = 'attachment; filename="' . $filename . '"; filename*=UTF-8\'\'' . rawurlencode($filename);
}

$this->response->setHeader("Content-Disposition", $contentDisposition);

Fortunately, Internet Explorer 7.0 and 8.0 are already dead, but Safari can still be a problem.

And yes, in any of these cases you don't need a semicolon at the end, but the filename must be enclosed in quotes.

sergeyklay added a commit that referenced this issue Aug 30, 2019
Fixes #13919, make response->setFileToSend support non-ASCII filename.
@sergeyklay
Copy link
Contributor

Fixed in the 4.0.x branch. Feel free to open a new issue if the problem appears again. Thank you for the bug report.

@ian4hu ian4hu mentioned this issue Sep 1, 2019
5 tasks
@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
@niden niden moved this to Unverified - Wont Fix - Duplicates in Phalcon v5 Aug 25, 2022
@niden niden added this to Phalcon v5 Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
Archived in project
Development

No branches or pull requests

4 participants