2017-10-05 219 views
0

我有以下代碼: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 

所以,拉鍊應安裝。

+2

你試過設置display_errors嗎? https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – Andreah

+1

當你從服務器獲得一個500,你通常會發現寫到服務器日誌的東西,將找出問題的原因 –

+0

在上面添加了一個編輯,用google搜索zipArchive尋找答案。謝謝。 – tcoulson

回答

0
PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); 

這條線從這個link並升級到1.8.1解決了這一問題。

+0

將您自己的答案標記爲已接受。 –