Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:26:03+00:00 2026-05-14T03:26:03+00:00

When I am trying to download a file whose name has characters from languages

  • 0

When I am trying to download a file whose name has characters from languages like Chinese Japanese etc…. non ascii… the downloaded file name is garbled. How to rectify it.

I have tried to put charset=UTF-8 in the Content-type header property, but no success. Code below.

header("Cache-Control: ");// leave blank to avoid IE errors

header("Pragma: ");// leave blank to avoid IE errors

header("Content-type: application/octet-stream");

header("Content-Disposition: attachment; filename=\"".$instance_name."\"");

header("Content-length:".(string)(filesize($fileString)));

sleep(1);

fpassthru($fdl);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:26:03+00:00Added an answer on May 14, 2026 at 3:26 am

    Unfortunately there is currently not a single solution that works with all browsers.
    There are at least three “more obvious” approaches to the problem.

    a) Content-type: application/octet-stream; charset=utf-8 + filename=<utf8 byte sequence>
    e.g. filename=Москва.txt
    This is a violation of standards but firefox shows the name correctly. IE doesn’t.

    b) Content-type: application/octet-stream; charset=utf-8 + filename=<urlencode(utf8 byte sequence)>
    e.g. filename=%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0.txt
    This works with IE but not with firefox.

    c) providing the name as specified in rfc 2231
    e.g filename*=UTF-8''%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0.txt
    Again firefox supports this, IE doesn’t.

    for a more comprehensive comparison see http://greenbytes.de/tech/tc2231/


    edit: When I said that there is no single solution, I meant via header(‘…’). But there is something of a work around.
    When there is no usable filename=xyz header browsers use the basename of the path part of the url. I.e. for <a href="test.php/lala.txt"> both firefox and IE suggest lalala.txt as the filename.
    You can append extra path components after the actual path to your php script (when using apache’s httpd see http://httpd.apache.org/docs/2.1/mod/core.html#acceptpathinfo).
    E.g. if you have a file test.php in your document root and request it as http://localhost/test.php/x/y/z the variable $_SERVER['PATH_INFO'] will contain /x/y/z.
    Now, if you put a link like

    <a
      href="/test.php/download/moskwa/&#x41c;&#x43e;&#x441;&#x43a;&#x432;&#x430;"
    >
      &#x41c;&#x43e;&#x441;&#x43a;&#x432;&#x430;
    </a>
    

    in your document you can fetch the download/moskwa/... part and initiate the download of the file. Without sending any filename=… information both firefox and IE suggest the “right” name.
    You can even combine it with sending the name according to rfc 2231. That’s why I also put moskwa into the link. That would be the id the script uses to find the file it is supposed to send. The IE ignores the filename*=... information and still uses the basename part of the url to suggest a name. That means for firefox (and any other client that supports rfc 2231) the part after the id is meaningless* but for the IE (and other clients not supporting rfc 2231) it would be used for the name suggestion.
    self-contained example:

    <?php // test.php
    $files = array(
      'moskwa'=>array(
        'htmlentities'=>'&#x41c;&#x43e;&#x441;&#x43a;&#x432;&#x430;',
        'content'=>'55° 45′ N, 37° 37′ O'
      ),
      'athen'=>array(
        'htmlentities'=>'&#x391;&#x3b8;&#x3ae;&#x3bd;&#x3b1;',
        'content'=>'37° 59′ N, 23° 44′ O'
      )
    );
    
    
    $fileid = null;
    if ( isset($_SERVER['PATH_INFO']) && preg_match('!^/download/([^/]+)!', $_SERVER['PATH_INFO'], $m) ) {
      $fileid = $m[1];
    }
    
    if ( is_null($fileid) ) {
      foreach($files as $fileid=>$bar) {
        printf(
          '<a href="./test.php/download/%s/%s.txt">%s</a><br />', 
          $fileid, $bar['htmlentities'], $bar['htmlentities']
        );
      }  
    }
    else if ( !isset($files[$fileid]) ) {
      echo 'no such file';
    }
    else {
      $f = $files[$fileid];
      $utf8name = mb_convert_encoding($f['htmlentities'], 'utf-8', 'HTML-ENTITIES');
      $utf8name = urlencode($utf8name);
    
      header("Content-type: text/plain");
      header("Content-Disposition: attachment; filename*=UTF-8''$utf8name.txt");
      header("Content-length: " . strlen($f['content']));
      echo $f['content'];
    }
    

    *) That’s a bit like here on Stack Overflow. The link for this question is shown as

    http://stackoverflow.com/questions/2578349/while-downloading-filenames-from-non-english-languages-are-not-getting-displayed
    

    but it also works with

    http://stackoverflow.com/questions/2578349/mary-had-a-little-lamb
    

    the important part is the id 2578349

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 354k
  • Answers 354k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to do this through VBScript and load in… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer EDIT: I tried to clarify I bit more ... 1.… May 14, 2026 at 7:52 am
  • Editorial Team
    Editorial Team added an answer Read each line, stick the contents of the line into… May 14, 2026 at 7:52 am

Related Questions

I am running into a maven problem that's killing all my hairs. So at
I have written some code that makes use of an open source library to
I am trying to download a file I have uploaded to an image field
I am trying to download files from an ftp server using C# and ftpwebrequest.
I am trying to set up Maven with a Repository located in our local

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.