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