我有以下代码:phpoffice phpexcel不加载文件
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上的load并且给我一个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
所以,拉链应安装。
你试过设置display_errors吗? https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Andreah
当你从服务器获得一个500,你通常会发现写到服务器日志的东西,将找出问题的原因 –
在上面添加了一个编辑,用google搜索zipArchive寻找答案。谢谢。 – tcoulson