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

Error with zip #965

Open
carles9000 opened this issue Dec 20, 2016 · 6 comments
Open

Error with zip #965

carles9000 opened this issue Dec 20, 2016 · 6 comments

Comments

@carles9000
Copy link

carles9000 commented Dec 20, 2016

Hi Masters,

Many times, if you repeat and repeat the program (for exemple with F5), the system gives an error message that can not close the temporary file.

The following message appears on the screen:

Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 'Could not close zip file C:\Users\songoku\AppData\Local\Temp\Php9D8B.tmp.' in C:\xampp\htdocs\z\doc\src\PhpWord\Shared\ZipArchive.php:163 Stack trace: #0 C:\xampp\htdocs\z\doc\src\PhpWord\TemplateProcessor.php(412): PhpOffice\PhpWord\Shared\ZipArchive->close() #1 C:\xampp\htdocs\z\doc\src\PhpWord\TemplateProcessor.php(430): PhpOffice\PhpWord\TemplateProcessor->save() #2 C:\xampp\htdocs\z\doc\S07c.php(63): PhpOffice\PhpWord\TemplateProcessor->saveAs('reporting/outpu...') #3 {main} thrown in C:\xampp\htdocs\z\doc\src\PhpWord\Shared\ZipArchive.php on line 163

Any idea how I can solve this situation ?

Thanks for you help.
Carles


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@carles9000
Copy link
Author

carles9000 commented Dec 20, 2016

Hi again,

If you change zip engine, it seems like you run many times and it doesn't break

I make this exchange in the configuration

Settings::setZipClass( 'PclZip' );

but file.docx is corrupt

Thanks.
Carles.

@carles9000
Copy link
Author

carles9000 commented Dec 20, 2016

More info...

I write in ZipArchive.php, method Close() (+-line 162) the next:

    public function close()
    {
        if (!$this->usePclzip) {
            if ($this->zip->close() === false) {
		echo '<br>ERROR: ' . $this->zip->getStatusString() ;
                throw new Exception("Could not close zip file {$this->filename}.");
            }
        }

        return true;
    }

Then execute and this is the output

ERROR: Renaming temporary file failed: Invalid argument
Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 'Could not close zip file C:\Users\songoku\AppData\Local\Temp\PhpDF2F.tmp.' in C:\xampp\htdocs\z\doc\src\PhpWord\Shared\ZipArchive.php:164 Stack trace: #0 C:\xampp\htdocs\z\doc\src\PhpWord\TemplateProcessor.php(426): PhpOffice\PhpWord\Shared\ZipArchive->close() #1 C:\xampp\htdocs\z\doc\src\PhpWord\TemplateProcessor.php(448): PhpOffice\PhpWord\TemplateProcessor->save() #2 C:\xampp\htdocs\z\doc\S07d.php(44): PhpOffice\PhpWord\TemplateProcessor->saveAs('reporting/outpu...') #3 {main} thrown in C:\xampp\htdocs\z\doc\src\PhpWord\Shared\ZipArchive.php on line 164

The code is based in samples -> Sample_07_TemplateCloneRow.php

<?php
$vendorDirPath = 'vendor';

if (file_exists($vendorDirPath . '/autoload.php')) {
    require $vendorDirPath . '/autoload.php';
} else {
    throw new Exception(
        sprintf(
            'Could not find file \'%s\'. It is generated by Composer. Use \'install --prefer-source\' or \'update --prefer-source\' Composer commands to move forward.',
            $vendorDirPath . '/autoload.php'
        )
    );
}

use PhpOffice\PhpWord\Settings;

Settings::loadConfig('phpword.ini');

echo 'Tmp: ' . Settings::getTempDir();

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('reporting/plantillas/S07d.docx');

// Table with a spanned cell
$templateProcessor->cloneRow('userId', 3);

$templateProcessor->setValue('userId#1', '1');
$templateProcessor->setValue('userFirstName#1', 'James');
$templateProcessor->setValue('userName#1', 'Taylor');
$templateProcessor->setValue('userPhone#1', '+1 428 889 773');

$templateProcessor->setValue('userId#2', '2');
$templateProcessor->setValue('userFirstName#2', 'Tesxto largo de test 1. Tesxto largo de test 2. Tesxto largo de test 3. Tesxto largo de test 4. ');
$templateProcessor->setValue('userName#2', 'Bell');
$templateProcessor->setValue('userPhone#2', '+1 428 889 774');

$templateProcessor->setValue('userId#3', '3');
$templateProcessor->setValue('userFirstName#3', 'Michael');
$templateProcessor->setValue('userName#3', 'Ray');
$templateProcessor->setValue('userPhone#3', '+1 428 889 775');
$templateProcessor->setValue('userPhone#3', '');

echo '<br>' . date('H:i:s'), ' Saving the result document... '  ;

$templateProcessor->saveAs('reporting/output/S07d.doc');
?>

Finally i tried with phpword.ini

; Default config file for PHPWord
; Copy this file into phpword.ini and use Settings::loadConfig to load

[General]

compatibility         = true
zipClass              = ZipArchive
pdfRendererName       = DomPDF
pdfRendererPath       = /vendor/dompdf/dompdf
;tempDir               = "/C:\PhpWordTemp"
tempDir               = /reporting/tmp
outputEscapingEnabled = false

[Font]

defaultFontName = Arial
defaultFontSize = 10

I read this issues but i can not find the correct solution...

Ideas, suggestions, help, please?

Carles.

@florianp-dev
Copy link

Hi there, I just had the problem.

Simply change rights to the folder was successfully.

@vlyalko
Copy link

vlyalko commented Jun 17, 2019

@florianp-dev which folder rights needs to be changed for? /tmp?

@chrisribe
Copy link

Got this error when trying to open a .doc and not .docx (only open docx!)

@almokhtarbr
Copy link

Got this error when trying to open a .doc and not .docx (only open docx!)

any updates ?

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

5 participants