In the past few days, XAMPP has been installed in windows, so I am going to learn about php. I have encountered php file upload problems over the past few days, but I am going to upload an exce
In the past few days, XAMPP has been installed in windows, so I am going to learn about php. I have encountered php file upload problems over the past few days. However, I am going to upload an excel file, but if the file name is a Chinese name, an error will be reported.
One to two go is very depressed, and then think carefully should be a file encoding problem, I write php files using UTF-8 encoding, if you haven't guessed it wrong, the APACHE processing should use GBK (of course, I am not sure now, I hope the experts will give you advice). If you want to understand this problem, go to the relevant tutorials, simply find the iconv function.
Function prototype: string iconv (string in_charset, string out_charset, string str)
Example of use: $ content = iconv ("GBK", "UTF-8", $ content); this example is used to convert $ content from GBK to UTF-8 encoding, garbled key code:
- $ 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 characters in the uploaded files, we can rename the uploaded files. for example:
- $ SFileName = "sda. php ";
- $ SOriginalFileName = $ sFileName;
- $ SExtension = s str ($ sFileName, (strrpos ($ sFileName, '.') + 1); // locate the extension
- $ SExtension = strtolower ($ sExtension );
- $ SFileName = date ("YmdHis "). rand (100,200 ). ". ". $ sExtension; // This is the new file name, and there will be no garbled characters in the full number.