Uploadify plug-in uses thinkphp Ajaxreturn to return Unicode encoding?

Source: Internet
Author: User
    public function fileup(){        $upload = new \Think\Upload();// 实例化上传类        $upload->maxSize   =     1024*1024*2 ;// 设置附件上传大小        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg', 'zip', 'xls', 'rar');// 设置附件上传类型        $upload->rootPath  =     './Public/Uploads/'; // 设置附件上传根目录        $upload->savePath  =     ''; // 设置附件上传(子)目录        // 上传文件         $info   =   $upload->upload();        if(!$info) {// 上传错误提示错误信息            $this->ajaxReturn($upload->getError());        }else{// 上传成功            foreach ($info as $file) {                $data['filename'] = $file['name'];                $data['filepath'] = 'uploads/'.$file['savepath'].$file['savename'];                $data['filesize'] = $file['size'];                $this->ajaxReturn($data);            }        }    }

I am using the upploadify plugin to upload files, if the upload failed, will return an error message,
But $this->ajaxreturn ($upload->geterror ()); Is the Unicode encoding returned?

\u4e0a\u4f20\u6587\u4ef6\u540e\u7f00\u4e0d\u5141\u8bb8

Can you tell me why Unicode encoding is returned? Because of what?
Can't I display Chinese characters directly?

Reply content:

    public function fileup(){        $upload = new \Think\Upload();// 实例化上传类        $upload->maxSize   =     1024*1024*2 ;// 设置附件上传大小        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg', 'zip', 'xls', 'rar');// 设置附件上传类型        $upload->rootPath  =     './Public/Uploads/'; // 设置附件上传根目录        $upload->savePath  =     ''; // 设置附件上传(子)目录        // 上传文件         $info   =   $upload->upload();        if(!$info) {// 上传错误提示错误信息            $this->ajaxReturn($upload->getError());        }else{// 上传成功            foreach ($info as $file) {                $data['filename'] = $file['name'];                $data['filepath'] = 'uploads/'.$file['savepath'].$file['savename'];                $data['filesize'] = $file['size'];                $this->ajaxReturn($data);            }        }    }

I am using the upploadify plugin to upload files, if the upload failed, will return an error message,
But $this->ajaxreturn ($upload->geterror ()); Is the Unicode encoding returned?

\u4e0a\u4f20\u6587\u4ef6\u540e\u7f00\u4e0d\u5141\u8bb8

Can you tell me why Unicode encoding is returned? Because of what?
Can't I display Chinese characters directly?

Thinkphp's Ajaxreturn is to directly json_encode the kanji and return the output

You can first urlencode the Chinese characters and then json_encode the last UrlDecode.

Or if you just echo the information json_encode, the kanji will not be encoded into Unicode.

Do not have to use $this->ajaxReturn can be used directly json_encode , plus the second parameter is good SON_UNESCAPED_UNICODE (this parameter you use the version should be supported)
There's another suggestion. The data format that was returned with the failure is the same asjson
How do you write it in foreach there?$this->ajaxReturn

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.