Introduction
When I develop one of my cases, there is a requirement to generate a zip file. So I find a package laravel-zipstream
to do it.
Problem
Everything is fine until my customer told me files should be placed in a specific path which contains chinese characters. (´;ω;`)
At begining, I just change the filename like:
1 | $zip = Zip::create('user_data.zip'); |
But when I download this zip, I get something like:
Where is my filename and folder name :(
Identify Problem
At begining, I thought it’s some encoding problem. But I tried to change encoding and still got the same result.
So I went to looked up the source code, and found:
https://github.com/stechstudio/laravel-zipstream/blob/master/src/Models/File.php
1 | public function getZipPath(): string |
When config('zipstream.file.sanitize')
is true
, it will try to translate filename to ascii by Laravel’s Helper function Str::ascii()
(more information in official doc.).
Solve
So I looked up the package’s config.php
1 | // Default options for files added |
Thus, we can just add below line in our .env
to use non-ascii characters in filename!
1 | ZIPSTREAM_FILE_SANITIZE=true |
Additional information
Because I don’t see any description in README
about this feature, so I also open a PR in GitHub to add some description about it.
If you’re interested in it, you can find it here.