Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'ZipArchive' not found #1063

Closed
ahmednawazbutt opened this issue May 23, 2017 · 5 comments
Closed

Class 'ZipArchive' not found #1063

ahmednawazbutt opened this issue May 23, 2017 · 5 comments

Comments

@ahmednawazbutt
Copy link

ahmednawazbutt commented May 23, 2017

Hi everyone, I hope you all be fine.I am having some trouble using this extension on my Yii2 Application.

Here is the error log:

**Class 'ZipArchive' not found**

 in /home/ahmednawaz/Projects/ProjectName/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php at line 134
     * @param int $flags The mode to use to open the archive
     * @return bool
     */
    public function open($filename, $flags = null)
    {
        $result = true;
        $this->filename = $filename;
 
        if (!$this->usePclzip) {
            $zip = new \ZipArchive();
            $result = $zip->open($this->filename, $flags);
 
            // Scrutizer will report the property numFiles does not exist
            // See https://github.com/scrutinizer-ci/php-analyzer/issues/190
            $this->numFiles = $zip->numFiles;
        } else {
            $zip = new \PclZip($this->filename);
            $this->tempDir = Settings::getTempDir();
            $this->numFiles = count($zip->listContent());


Here is what I put in my view file

<?php

use PhpOffice\PhpWord\PhpWord;

$phpWord = new PhpWord();

$section = $phpWord->addSection();
$section->addText(
    '"Great achievement is usually born of great sacrifice, '
    . 'and is never the result of selfishness." '
    . '(Napoleon Hill)',
    array('name' => 'Tahoma', 'size' => 10)
    );

// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');

Here is what my controller action looks like

$model = $this->findModel($id);
        
        //  There is no such thing as rendereing here, I just want to see what happends with phpWord
        $this->render('test', ['model' => $model]);
@ahmednawazbutt
Copy link
Author

May be this could be due to multiple ZipArchive classes (one in the core and the other in the extension. I have personally accessed the open method of phpword/src/shared/zipArchive class and tried to jump to \ZipArchive() and it leads straight to core API method, still I get the error even if the chain-links are correct.
I have no idea what is the issue.

Any help is appreciated.

@ahmednawazbutt
Copy link
Author

The issue was resolved. All I had to do was:
\PhpOffice\PhpWord\Settings::setZipClass(Settings::PCLZIP); before processing file

Its working now.
Thanks to:
https://stackoverflow.com/questions/26643775/class-ziparchive-not-found-error-while-using-phpexcel

@virajkadam
Copy link

virajkadam commented Apr 27, 2020

The issue was resolved. All I had to do was:
\PhpOffice\PhpWord\Settings::setZipClass(Settings::PCLZIP); before processing file

Its working now.
Thanks to:
https://stackoverflow.com/questions/26643775/class-ziparchive-not-found-error-while-using-phpexcel

WORKED LIKE A CHARM. Thank You so much Brother.
It worked for me for PHPWORD.

My Settings :

// importing settings via namespace
use PhpOffice\PhpWord\Settings;

// calling settings right above file generation. (As stated in this answer)
Settings::setZipClass(Settings::PCLZIP);

// Save file
echo write($phpWord, basename(__ FILE __, '.php'), $writers);

// ----------- OR ----------------------------------------

// just paste this part in Sample_Header.php as below.

Settings::loadConfig();

// put below line after loadConfig, as both loadConfig & setZipClass are functions of same settings class.
Settings::setZipClass(Settings::PCLZIP);

@lbermudezd
Copy link

Thank you!!! @ahmednawazbutt

@Andresalfaro7
Copy link

Thankyou very much! @virajkadam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants