我正在使用库PHPExcel在PHP中创建一个Web应用程序,一个功能是将xls文件转换为xlsx。这是功能的代码:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../PHPExcel/Classes/');
include 'PHPExcel/IOFactory.php';
$excelPath="/Documents/Excel/";
$inputFileName=$_FILES['file']['name'];
$fileType=$_FILES['file']['type'];
$fileSize=$_FILES['file']['size'];
$fileTemp=$_FILES['file']['tmp_name'];
$extension = substr(strrchr($inputFileName, '.'), 1);
if ($extension=="xls"){
$fileName= "list_file_to_convert.xls";
$save_as= $excelPath.$fileName;
move_uploaded_file($fileTemp, $save_as);
$inputFileType = PHPExcel_IOFactory::identify($save_as);
$excel = PHPExcel_IOFactory::load($save_as);
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save($excelPath."test123.xlsx");
}else{
echo "everything is ok, a file xlsx has been loaded";
}
?>
问题是,当我尝试使用该功能时:
PHPExcel_IOFactory ::负载($ save_as);
我收到以下错误:
奇怪的是,如果我使用xlsx格式或CVS文件加载文件,并转换为xls或CVS,一切正常,但只有在文件加载了xls扩展名时才会生成错误。我做错了什么?