In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to solve the problem of garbled names in Chinese files uploaded by php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the problem of garbled names in Chinese files uploaded by php".
In the past few days, XAMPP has been installed under windows, ready to learn the relevant content of php. These days came into contact with the php upload file, but there is a depressed problem, I am going to upload an excel file, but if the file name is Chinese, it will report an error.
It was very depressing to come and go, and later I thought carefully that it should be the problem of file coding. I wrote the php file using UTF-8 encoding, and if I guessed correctly, APACHE processing should use GBK (of course, now I am not sure, I hope the master will give me advice). Want to understand this problem, to find the relevant tutorials, simply found the function iconv.
Function prototype: string iconv (string in_charset, string out_charset, string str)
Use example: $content = iconv ("GBK", "UTF-8", $content)
The purpose of this example is to convert $content from GBK to UTF-8 encoding.
Key code of garbled problem:
The copy code is as follows:
$name=iconv ("UTF-8", "gb2312", $name)
Move_uploaded_file ($tmpname, $this- > final_file_path)
$name=iconv ("gb2312", "UTF-8", $name)
In addition to solving the problem of Chinese garbled in uploaded files, we can also rename uploaded files.
Example
The copy code is as follows:
$sFileName = "sda.php"
$sOriginalFileName = $sFileName
$sExtension = s str ($sFileName, (strrpos ($sFileName,'.) + 1)); / / find the extension
$sExtension = strtolower ($sExtension)
$sFileName = date ("YmdHis"). Rand (100,200). ". $sExtension; / / this is our new file name, and there will be no garbled code for all-digital ones.
Here are some additions:
Solution of garbled File name uploaded by php in Chinese
The copy code is as follows:
$filepath= "upload/"
$name=$filepath.$_FILES ["upfile"] ["name"]
While (file_exists ($name)) {
$temp=explode (".", $name); / / split the string
$name=$temp [0]. "0". $temp [1]; / / add 0 after the main file name
}
The copy code is as follows:
/ / the iconv () function is the key
If (move_uploaded_file ($_ FILES ["upfile"] ["tmp_name"], iconv ("UTF-8", "gb2312", $name)) {/ / process.}
My PHP code is UTF-8, probably because the operating system is GBK!
Note: my server is windows xp, apache, and the estimated xp character set is gbk. Because my php code is saved in utf-8 format, there will be garbled when naming the file name, so you can use the iconv () function to convert the original utf-8 format file name to gbk format.
The solution of garbled File name in php utf8 Encoding and uploading
Presumably many friends in the utf8 coding php development upload function, will encounter such a problem, that is, upload the Chinese file name, the file name will become garbled, we can use the iconv function to re-encode the file name to solve the problem.
The copy code is as follows:
At this point, I believe you have a deeper understanding of "how to solve the problem of garbled names in Chinese files uploaded by php". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.