背景
iconv(): Detected an illegal character in input string
报错信息
如下:
{
"name": "PHP Notice",
"message": "iconv(): Detected an illegal character in input string",
"code": 8,
"type": "yii\\base\\ErrorException",
"file": "/usr/share/nginx/html/ycsh_automat/Classes/PHPExcel/Shared/String.php",
"line": 490,
"stack-trace": [
"#0 [internal function]: yii\\base\\ErrorHandler->handleError(8, 'iconv(): Detect...', '/usr/share/ngin...', 493, Array)",
"#1 /usr/share/nginx/html/ycsh_automat/Classes/PHPExcel/Shared/String.php(490): iconv('CP1252', 'UTF-8', '\\xE8\\xAE\\xA2\\xE5\\x8D\\x95\\xE5\\x88\\x97\\xE8\\xA1\\xA8\\x00\\x00\\x00...')",
"#2 /usr/share/nginx/html/ycsh_automat/Classes/PHPExcel/Reader/Excel5.php(1362): PHPExcel_Shared_String::ConvertEncoding('\\xE8\\xAE\\xA2\\xE5\\x8D\\x95\\xE5\\x88\\x97\\xE8\\xA1\\xA8\\x00\\x00\\x00...', 'UTF-8', 'CP1252')",
"#3 /usr/share/nginx/html/ycsh_automat/Classes/PHPExcel/Reader/Excel5.php(633): PHPExcel_Reader_Excel5->readSummaryInformation()",
"#4 /usr/share/nginx/html/ycsh_automat/Classes/PHPExcel/IOFactory.php(192): PHPExcel_Reader_Excel5->load('/usr/share/ngin...')",
"#5 /usr/share/nginx/html/ycsh_automat/common/services/ExcelMzService.php(154): PHPExcel_IOFactory::load('/usr/share/ngin...')",
"#6 /usr/share/nginx/html/ycsh_automat/common/models/ExportTask.php(306): common\\services\\ExcelMzService->cronCreateExportFile(Array, Array, '/usr/share/ngin...', Array, '\\xE8\\xAE\\xA2\\xE5\\x8D\\x95\\xE5\\x88\\x97\\xE8\\xA1\\xA8')",
"#7 /usr/share/nginx/html/ycsh_automat/api/controllers/CronController.php(54): common\\models\\ExportTask::execExportTask(Object(common\\models\\ExportTask), 1, '{\"search_params...')",
"#8 [internal function]: api\\controllers\\CronController->actionRunExportTask()",
...
}
问题分析
PHPExcel_IOFactory::load()
方法时,因为文件名编码问题造成程序中断Classes\PHPExcel\Shared\String.php
的 ConvertEncoding()
方法的的第一个条件判断不满足解决方案
Classes\PHPExcel\Shared\String.php
的 ConvertEncoding()
方法的的第一个条件判断,如下
附录
windows
环境中,不会报错,只有上传到 Linux
服务器,才会有报错!