Home >Backend Development >PHP Problem >How to solve the Chinese garbled code in php swfupload

How to solve the Chinese garbled code in php swfupload

青灯夜游
青灯夜游Original
2021-05-21 16:45:222472browse

Method: 1. Use the "fileName=new String(fileName.getBytes("UTF-8"), "GBK")" statement; 2. Use "fileName=URLDecoder.decode(fileName,"UTF- 8")" statement.

How to solve the Chinese garbled code in php swfupload

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

SWFUpload Chinese garbled problem, on the Internet Search the posts, there are many solutions to this problem.

The first one: fileName= new String(fileName.getBytes("UTF-8"),"GBK");
This method can solve most of the garbled characters. However, if there are special characters and punctuation marks in the file name, it may not be converted sometimes.

Second: I used this method, and the test has passed

/**在设置时需要设置一下上传事件 
  *upload_start_handler : UploadStart, 
  *动态传参数,解决文件名中文乱码问题 
**/  
function uploadStart(file) {
	try {
		/* I don't want to do any file validation or anything,  I'll just update the UI and return true to indicate that the upload should start */
		var progress = new FileProgress(file, this.customSettings.progressTarget);
		
		//progress.setStatus("Uploading...");
		progress.setStatus("上传中...");
		progress.toggleCancel(true, this);
		this.setPostParams({ 
			  'fileName':encodeURIComponent(file.name) 
			  }); 
	}
	catch (ex) {
	}
	
	return true;
}

Used in action

fileName = URLDecoder.decode(fileName,"UTF-8");

Recommended learning: "PHP Video Tutorial

The above is the detailed content of How to solve the Chinese garbled code in php swfupload. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn