首頁  >  文章  >  後端開發  >  php swfupload中文亂碼怎麼解決

php swfupload中文亂碼怎麼解決

青灯夜游
青灯夜游原創
2021-05-21 16:45:222376瀏覽

方法:1、利用「fileName=new String(fileName.getBytes("UTF-8"),"GBK")」語句;2、利用「fileName=URLDecoder.decode(fileName,"UTF- 8")」語句。

php swfupload中文亂碼怎麼解決

本教學操作環境:windows7系統、PHP7.1版,DELL G3電腦

SWFUpload中文亂碼問題,在網路上搜尋的帖子,關於這個問題的解決方法有很多。

第一種:fileName= new String(fileName.getBytes("UTF-8"),"GBK");
用這種方式可以解決大部分亂碼,但如果檔案名稱中有特殊字元和標點符號有時候會轉不過來。

第二種:我使用的是這種方法,測試已經透過 

/**在设置时需要设置一下上传事件 
  *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;
}

在action中使用 

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

推薦學習:《PHP影片教學

#

以上是php swfupload中文亂碼怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn