phpoffice phpexcel 不加载文件
phpoffice phpexcel not loading file
我有以下代码:
require_once "../vendor/autoload.php";
require_once '../vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
$target_dir = "coverImages/";
$target_file = $target_dir . basename($_FILES["excelfile"]["name"]);
move_uploaded_file($_FILES["excelfile"]["tmp_name"], $target_file);
if ($_FILES["excelfile"]["error"] > 0)
{
echo "Error: " . $_FILES["excelfile"]["error"] . "<br>";
}
else
{
if (file_exists($target_file)) {
echo "file exists!";
}else{
echo "oh it does not";
}
$objPHPExcel = PHPExcel_IOFactory::load($target_file);
}
我正在从输入文件中获取文件。我正在将文件移动到服务器上的某个位置。但是一旦我移动了文件,我就无法加载它。我正在验证该文件是否存在,但是当我在 Factory 上调用加载并给我一个 500 错误时,phpoffice 不会获取我的文件。任何建议都可以帮助我,在此先感谢。
编辑:返回错误:
Fatal error: Uncaught Error: Class 'ZipArchive' not found in
/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php:94
Stack trace: #0
/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(268):
PHPExcel_Reader_Excel2007->canRead('coverImages/Boo...') #1
/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(191):
PHPExcel_IOFactory::createReaderForFile('coverImages/Boo...') #2
/app/public/upload_file.php(26):
PHPExcel_IOFactory::load('coverImages/Boo...') #3 {main} thrown in
/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php
on line 94
不确定为什么会出现错误,在我调用的 dockerfile 中:
RUN apt-get update && \
apt-get install -y \
freetds-dev \
libsybdb5 \
wget \
zip
所以应该安装zip。
您缺少 zip
扩展名。在您的 php.ini 文件中允许它或安装它。
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
此 link 中的这一行和升级到 1.8.1 解决了这个问题。
我有以下代码:
require_once "../vendor/autoload.php";
require_once '../vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php';
$target_dir = "coverImages/";
$target_file = $target_dir . basename($_FILES["excelfile"]["name"]);
move_uploaded_file($_FILES["excelfile"]["tmp_name"], $target_file);
if ($_FILES["excelfile"]["error"] > 0)
{
echo "Error: " . $_FILES["excelfile"]["error"] . "<br>";
}
else
{
if (file_exists($target_file)) {
echo "file exists!";
}else{
echo "oh it does not";
}
$objPHPExcel = PHPExcel_IOFactory::load($target_file);
}
我正在从输入文件中获取文件。我正在将文件移动到服务器上的某个位置。但是一旦我移动了文件,我就无法加载它。我正在验证该文件是否存在,但是当我在 Factory 上调用加载并给我一个 500 错误时,phpoffice 不会获取我的文件。任何建议都可以帮助我,在此先感谢。
编辑:返回错误:
Fatal error: Uncaught Error: Class 'ZipArchive' not found in /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php:94 Stack trace: #0 /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(268): PHPExcel_Reader_Excel2007->canRead('coverImages/Boo...') #1 /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php(191): PHPExcel_IOFactory::createReaderForFile('coverImages/Boo...') #2 /app/public/upload_file.php(26): PHPExcel_IOFactory::load('coverImages/Boo...') #3 {main} thrown in /app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php on line 94
不确定为什么会出现错误,在我调用的 dockerfile 中:
RUN apt-get update && \
apt-get install -y \
freetds-dev \
libsybdb5 \
wget \
zip
所以应该安装zip。
您缺少 zip
扩展名。在您的 php.ini 文件中允许它或安装它。
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
此 link 中的这一行和升级到 1.8.1 解决了这个问题。