<legend id='VCkGs'><style id='VCkGs'><dir id='VCkGs'><q id='VCkGs'></q></dir></style></legend>
    <bdo id='VCkGs'></bdo><ul id='VCkGs'></ul>

    <tfoot id='VCkGs'></tfoot>

    1. <small id='VCkGs'></small><noframes id='VCkGs'>

    2. <i id='VCkGs'><tr id='VCkGs'><dt id='VCkGs'><q id='VCkGs'><span id='VCkGs'><b id='VCkGs'><form id='VCkGs'><ins id='VCkGs'></ins><ul id='VCkGs'></ul><sub id='VCkGs'></sub></form><legend id='VCkGs'></legend><bdo id='VCkGs'><pre id='VCkGs'><center id='VCkGs'></center></pre></bdo></b><th id='VCkGs'></th></span></q></dt></tr></i><div id='VCkGs'><tfoot id='VCkGs'></tfoot><dl id='VCkGs'><fieldset id='VCkGs'></fieldset></dl></div>

      PHP - 上传 utf-8 文件名

      时间:2023-05-20

      <small id='T8yZa'></small><noframes id='T8yZa'>

        <bdo id='T8yZa'></bdo><ul id='T8yZa'></ul>
        <tfoot id='T8yZa'></tfoot>
        <i id='T8yZa'><tr id='T8yZa'><dt id='T8yZa'><q id='T8yZa'><span id='T8yZa'><b id='T8yZa'><form id='T8yZa'><ins id='T8yZa'></ins><ul id='T8yZa'></ul><sub id='T8yZa'></sub></form><legend id='T8yZa'></legend><bdo id='T8yZa'><pre id='T8yZa'><center id='T8yZa'></center></pre></bdo></b><th id='T8yZa'></th></span></q></dt></tr></i><div id='T8yZa'><tfoot id='T8yZa'></tfoot><dl id='T8yZa'><fieldset id='T8yZa'></fieldset></dl></div>

                  <tbody id='T8yZa'></tbody>

                <legend id='T8yZa'><style id='T8yZa'><dir id='T8yZa'><q id='T8yZa'></q></dir></style></legend>

              • 本文介绍了PHP - 上传 utf-8 文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我是越南人,我想上传一个 utf-8 文件名

                I'm Vietnamese and i want to upload a utf-8 filename like

                Tên Tệp Tiếng Việt.JPG

                这是我的代码

                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
                <html xmlns="http://www.w3.org/1999/xhtml"> 
                <head> 
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
                <title>utf-8</title> 
                </head> 
                
                <body> 
                <?php
                    if(isset($_POST["submit"])) { 
                       if($_FILES["upload"]["error"] > 0 ) echo "FILE ERROR!"; 
                       else 
                         { 
                           $base_dir = "D:/"; 
                           $fn = $_FILES["upload"]["name"]; 
                
                           $fn2 = $base_dir.$fn;
                
                           move_uploaded_file($_FILES["upload"]["tmp_name"],$fn2); 
                         } 
                     } 
                ?> 
                <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
                  <input type="file" name="upload" id="upload" /> 
                  <input type="submit" name="submit" id="submit" value="Send" /> 
                </form> 
                </body> 
                </html> 
                

                但是当我上传我在我的电脑上看到的 D: 有一个类似的文件

                but when i upload that i see on my computer D: has a file like

                Tên Tệp Tiếng Việt.JPG

                如何解决这个问题,谢谢

                How to fix that thanks

                推荐答案

                我使用的是 Windows 8 中文版,我遇到了类似的问题:

                I'm on Windows 8 chinese version, and I deal with similar problem with this:

                $filename = iconv("utf-8", "cp936", $filename);
                

                cp 代表 代码页cp936 代表 代码页936,这是简体中文版Windows的默认代码页.

                cp stands for Code page and cp936 stands for Code page 936, which is the default code page of simplified chinese version of Windows.

                <打击>所以我想也许你的问题可以用类似的方式解决:

                So I think maybe your problem could be solved in a similar way:

                $fn2 = iconv("UTF-8","cp1258", $base_dir.$fn);
                

                我不太确定您操作系统的默认代码页是否为 1258,您应该通过打开命令提示符并输入命令 chcp 自行检查.然后将 1258 更改为命令给您的任何内容.

                I'm not quite sure whether the default code page of your OS is 1258 or not, you should check it yourself by opening command prompt and type in command chcp. Then change 1258 to whatever the command give you.

                更新

                根据这个答案,PHP 文件系统函数似乎只能处理系统代码页中的字符.所以你在这里有 2 个选择:

                It seems that PHP filesystem functions can only handle characters that are in system codepage, according to this answer. So you have 2 choices here:

                1. 将文件名中的字符限制为系统代码页 - 在您的情况下,它是 437.但我很确定代码页 437 不包括所有越南语字符.

                1. Limit the characters in the filename to system codepage - in your case, it's 437. But I'm pretty sure that code page 437 does not include all the vietnamese characters.

                将您的系统代码页更改为越南语:1258 并将文件名转换为 cp1258.然后文件系统功能应该可以工作.

                Change your system codepage to the vietnamese one: 1258 and convert the filename to cp1258. Then the filesystem functions should work.

                两种选择都有缺陷:

                选择 1:您不能再使用越南语字符,这不是您想要的.

                Choice 1: You can't use vietnamese characters anymore, which is not what you want.

                选择 2:您必须更改系统代码页,并且文件名字符限制为代码页 1258.

                Choice 2: You have to change system code page, and filename characters are limited to code page 1258.

                更新

                如何更改系统代码页:

                转到控制面板 > Region > Administrative > Change system locale 并选择Vietnamese(越南) 在下拉菜单中.

                Go to Control Panel > Region > Administrative > Change system locale and select Vietnamese(Vietnam) in the drop down menu.

                这篇关于PHP - 上传 utf-8 文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何上传 &amp;使用所需名称保存文件 下一篇:使用 file_get_contents 上传文件

                相关文章

                最新文章

              • <small id='pjvnb'></small><noframes id='pjvnb'>

                    <bdo id='pjvnb'></bdo><ul id='pjvnb'></ul>
                  <legend id='pjvnb'><style id='pjvnb'><dir id='pjvnb'><q id='pjvnb'></q></dir></style></legend>
                1. <i id='pjvnb'><tr id='pjvnb'><dt id='pjvnb'><q id='pjvnb'><span id='pjvnb'><b id='pjvnb'><form id='pjvnb'><ins id='pjvnb'></ins><ul id='pjvnb'></ul><sub id='pjvnb'></sub></form><legend id='pjvnb'></legend><bdo id='pjvnb'><pre id='pjvnb'><center id='pjvnb'></center></pre></bdo></b><th id='pjvnb'></th></span></q></dt></tr></i><div id='pjvnb'><tfoot id='pjvnb'></tfoot><dl id='pjvnb'><fieldset id='pjvnb'></fieldset></dl></div>

                    <tfoot id='pjvnb'></tfoot>