我有以下代码:
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);
}我正在从输入文件中获取该文件。我正在将文件移动到服务器上的某个位置。但是,一旦文件被移动,我就无法加载它。我正在验证文件是否存在,但是当我调用一个工厂上的load并给我500个错误时,phpoffice不会抓取我的文件。任何建议都能帮到我,谢谢。
编辑:错误返回:
致命错误:未捕获错误:在/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php:94堆栈跟踪中找不到类“ZipArchive”:#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):在第94行的/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php中抛出/app/vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php #3 {main}
不知道为什么会出现错误,在我调用的dockerfile中:
RUN apt-get update && \
apt-get install -y \
freetds-dev \
libsybdb5 \
wget \
zip所以应该安装拉链。
发布于 2017-10-06 13:17:58
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);这一行从这个链接升级到1.8.1,解决了这个问题。
发布于 2017-10-06 12:58:52
您错过了zip扩展。要么允许它进入您的php.ini文件,要么安装它。
https://stackoverflow.com/questions/46594884
复制相似问题