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

php 中文文件名下载 #102

Open
yangweijie opened this issue May 8, 2024 · 0 comments
Open

php 中文文件名下载 #102

yangweijie opened this issue May 8, 2024 · 0 comments

Comments

@yangweijie
Copy link
Owner

两种

  1. 文件名转gbk
        $text = '2024年4月15日商品导出';
        $filename = mb_convert_encoding($text, "GBK",  "UTF-8").'.txt';   // a filename in Chinese characters
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: filename='.$filename);
        readfile(realpath('../think'));
        exit();
  1. urlencode
      $filename = '2024年4月5日中文文件名.txt';   // a filename in Chinese characters
      $contentDispositionField = 'Content-Disposition: attachment; '
          . sprintf('filename="%s"; ', rawurlencode($filename))
          . sprintf("filename*=utf-8''%s", rawurlencode($filename));
      header('Content-Type: application/octet-stream');
      header($contentDispositionField);
      readfile(realpath('../think'));
      exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant