How to solve the problem that Chinese file names will be garbled when uploading files in php?

I use wamp, to implement the file upload function if the file name uploaded is Chinese, it will be garbled , but the information in the database is correct . How to solve this?
in addition, when accepting form information to create a folder, if it is in Chinese, the name of the created folder will also be garbled.

if($image_files = request()->file("image_uploads"))
        {
            foreach($image_files as $file){
                $info = $file->move(ROOT_PATH . "public" . DS ."static" . "\\" . $title ."\\". "Picture" ,"");
                if($info){
                    $path_parts = pathinfo(ROOT_PATH . "public" . DS . "static" ."\\". $info->getFilename());
                    //
                    $type=$path_parts["extension"];
                    $name=$path_parts["filename"];
                    $size=(filesize(ROOT_PATH . "public" .DS. "static" ."\\".  $title ."\\". "Picture" . "\\" .$info->getFilename())>>10)."KB";
                    $data=["name"=>$name,"type"=>$type,"size"=>$size,"activity_id"=>$activityId];
                    Db::table("file")->insert($data);
                }else{
                    //
                    $this->error($file->getError());    
                }
                $upload_status = 1;
            }
Mar.09,2021

if you save the Chinese name directly when saving the file, note that the file name of windows is encoded by gbk, and you should use utf8, that needs to be converted.

however, it is not recommended to save the original file name directly. It is recommended to use the file name + timestamp, md5 encrypted string, and the real file name is only saved in the database.

because if one day you want to put the program in linux, you will encounter problems with the file name in Chinese.


the file name of windows is

of gbk.
Menu