2. Add mysql_query("set names 'encoding'"); before the PHP program that needs to do database operations. The encoding is consistent with the PHP encoding. If the PHP encoding is gb2312, then the mysql encoding is gb2312. If it is utf-8, then the mysql encoding is utf8, so that there will be no garbled characters when inserting or retrieving data Three, php is related to the operating system The encoding of Windows and Linux is different. In the Windows environment, if the parameters are UTF-8 encoded when calling PHP functions, errors will occur, such as move_uploaded_file(), filesize(), readfile(), etc. These functions are processing It is often used when uploading and downloading, and errors may occur when calling: warning: move_uploaded_file()[function.move-uploaded-file]: failed to open stream: invalid argument in ... warning: move_uploaded_file()[function.move-uploaded-file]:unable to move '' to '' in ... warning: filesize() [function.filesize]: stat failed for ... in ... warning: readfile() [function.readfile]: failed to open stream: invalid argument in .. Although these errors will not occur when using gb2312 encoding in the Linux operating system, the saved file name will be garbled and the file cannot be read. In this case, you can first convert the parameters into the encoding recognized by the operating system. For encoding conversion, you can use mb_convert_encoding (character String, new encoding, original encoding) or iconv (original encoding, new encoding, string), so that the file name saved after processing will not be garbled, and the file can be read normally to achieve uploading and downloading of Chinese name files. The better solution is to completely disconnect from the system, without considering the encoding of the system. You can generate a sequence of only letters and numbers as the file name, and save the original name with Chinese characters in the database. In this way, there will be no problem when calling move_uploaded_file(). When downloading, you only need to change the file name to the original name with Chinese characters. name. Example, code to implement downloading:
$file_type is the type of file, $file_name is the original name, $file_path is the file saved in The address of the file on the service. |