背景

报错信息 如下

{
	"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()", 
	  ...
}

问题分析

  1. 根据详细报错信息可以知道,是执行 PHPExcel_IOFactory::load() 方法时,因为文件名编码问题造成程序中断
  2. 业务场景中,即在分步追加 excel文件数据加载文件名时,识别转码有误
  3. 继而定位ClassesPHPExcelSharedString.phpConvertEncoding() 方法的的第一个条件判断不满足

解决方案

附录

  1. 网上的经验,基本php iconv() : Detected an illegal character in input string, 测试发现都无法解决我的问题
  2. 重点提示当前报错,在 windows 环境中,不会报错,只有上传Linux 服务器,才会有报错

原文地址:https://blog.csdn.net/u011415782/article/details/134638047

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_20650.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注