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

Develop branch template not saving? #238

Closed
ozilion opened this issue May 14, 2014 · 21 comments
Closed

Develop branch template not saving? #238

ozilion opened this issue May 14, 2014 · 21 comments

Comments

@ozilion
Copy link
Contributor

ozilion commented May 14, 2014

Using template cant save it and it stop at line that it should throw an excepted but there is no any thrown exception

public function save()
{
    foreach ($this->headerXMLs as $index => $headerXML) {
        $this->zipClass->addFromString($this->getHeaderName($index), $this->headerXMLs[$index]);
    }

    $this->zipClass->addFromString('word/document.xml', $this->documentXML);

    foreach ($this->footerXMLs as $index => $headerXML) {
        $this->zipClass->addFromString($this->getFooterName($index), $this->footerXMLs[$index]);
    }

    // Close zip file
    if ($this->zipClass->close() === false) {
      echo "save ok 1<br>"; // I can see written "save ok 1" on my browser
        throw new Exception('Could not close zip file.'); // this line is not working and can't pass to next line
      echo "save ok 2<br>"; // can't get to here
    }
      echo "save ok 3<br>";

    return $this->tempFileName;
}
@ivanlanin ivanlanin added the Bug label May 14, 2014
@ivanlanin ivanlanin added this to the 0.11.0 milestone May 14, 2014
@ozilion
Copy link
Contributor Author

ozilion commented May 24, 2014

I know everyone is busy but is there any progress on this issue? I need to use new version as soon as possible.

@ivanlanin
Copy link
Contributor

Sorry. I missed this one. I'll try to reproduce the error today.

@ivanlanin
Copy link
Contributor

I can't reproduce the error. I can run both Sample_07_TemplateCloneRow and Sample_23_TemplateBlock in the samples folder. Can you try to run those samples? If you can run those samples and get the docs, we can narrow the problem to be more specific to your case, i.e. your particular template or code.

@ozilion
Copy link
Contributor Author

ozilion commented May 27, 2014

I have tried them in two different computer one desktop and one laptop with windows 8.1 update 1 x64 but not working both samples and my own template files.

there is no specific code just load template, set value and save final result in Word2007 format

@ivanlanin
Copy link
Contributor

Hi @ozilion. We need more information to try to solve your issue.

  1. Which PHP version are you using?
  2. Can you run any other samples?
  3. Were there any warning/error messages?

@ozilion
Copy link
Contributor Author

ozilion commented May 28, 2014

  1. PHP ver: 5.3.28
  2. I can successfully create new word document has many tables, texts and finally I can add checkbox and save it as i desired.
  3. There is no any error messages as I already use error_reporting(E_ALL); and also defined in php.ini

Currently we still using old 0.6.2_beta version working great without checkbox feature.

@ivanlanin
Copy link
Contributor

Thanks for the info. So it's confirmed that all samples are working except the two samples that are related to template and there's no error messages for that. The problem is I still can't reproduce the bug that you're facing in my machine. If I can do that, it will be easier for me to help to solve the issue. I'll try to use a VM.

@ivanlanin ivanlanin modified the milestones: 0.12.0, 0.11.0 Jun 1, 2014
@ivanlanin ivanlanin self-assigned this Jun 1, 2014
@ozilion
Copy link
Contributor Author

ozilion commented Jun 2, 2014

Hi @ivanlanin I tried template samples with new version on Ubuntu 64bit using a VM and working as expected. Under windows there is a problem and I think it is because of my PHP configuration.

When I put some echos for debuging to catch the line where the code cut of to run and on my side any "throw new Exception(..." lines doesn't working, and I tried examples on this link http:https://www.php.net/manual/en/language.exceptions.php on a new file it's working.

@ozilion
Copy link
Contributor Author

ozilion commented Jun 2, 2014

I changed my PHP version to latest and here are what i found on php_errors.log file
[02-Jun-2014 15:30:58 Asia/Muscat] PHP Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in D:\wwwroot\PHPWord\src\PhpWord\Shared\ZipArchive.php on line 198
[02-Jun-2014 15:30:58 Asia/Muscat] PHP Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in D:\wwwroot\PHPWord\src\PhpWord\Shared\ZipArchive.php on line 201
[02-Jun-2014 15:30:58 Asia/Muscat] PHP Fatal error: Class 'PhpOffice\PhpWord\Exception' not found in D:\wwwroot\PHPWord\src\PhpWord\Template.php on line 186

@ivanlanin
Copy link
Contributor

Ok. I'll investigate this on Windows 8.1 x64 VM tonight or tomorrow. Thanks again for the report.

@ozilion
Copy link
Contributor Author

ozilion commented Jun 2, 2014

this is the last update for error log
[02-Jun-2014 15:43:38 Asia/Muscat] PHP Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in D:\wwwroot\PHPWord\src\PhpWord\Shared\ZipArchive.php on line 198
[02-Jun-2014 15:43:38 Asia/Muscat] PHP Warning: ZipArchive::getFromName(): Invalid or unitialized Zip object in D:\wwwroot\PHPWord\src\PhpWord\Shared\ZipArchive.php on line 201
[02-Jun-2014 15:43:38 Asia/Muscat] PHP Fatal error: Uncaught exception 'PhpOffice\PhpWord\Exception\Exception' with message 'Can not clone row, template variable not found or variable contains markup.' in D:\wwwroot\PHPWord\src\PhpWord\Template.php:186
Stack trace:
#0 D:\wwwroot\PHPWord\samples\Sample_07_TemplateCloneRow.php(16): PhpOffice\PhpWord\Template->cloneRow('rowValue', 10)
#1 {main}
thrown in D:\wwwroot\PHPWord\src\PhpWord\Template.php on line 186

@ivanlanin
Copy link
Contributor

Hm, that means PHPWord can't read from the document.xml. There's probably something in Windows 8.1 that prevents reading.

@ozilion
Copy link
Contributor Author

ozilion commented Jun 2, 2014

Hi again, I think I solved it. after I upgraded to PHP 5.5.13 phpMyAdmin started to give invalid token error and solved it by giving read/write permission to c:/windows/temp folder for local windows user. This permission changes also solved template problem.

In pclzip.lib.php file i tried to define( 'PCLZIP_TEMPORARY_DIR', 'C:/temp/' ); line but not worked, may be that was the wrong place to define custom temporary folder path.

@Progi1984
Copy link
Member

It may be this one.

PclZip, in its documentation, says :

By default these temporary files are created in the current working folder. 
This can be a problem in some situation (for example if the folder is read-only).

Source : http:https://www.phpconcept.net/pclzip/user-guide/23#parameter_PCLZIP_TEMPORARY_DIR

@ozilion
Copy link
Contributor Author

ozilion commented Jun 2, 2014

Ok. We can close this issue but if not exists there should be a line in documentation or readme files a for windows users to give apropriate read/write permissions for temp folder where defined in php.ini file, because as I see PHPWord uses get_sys_temp_dir() function to get path and as default it is c:/windows/temp on windows.

Now I am happy that I can upgrade our projet to latest version of PHPWord 👍 :)

@ozilion ozilion closed this as completed Jun 2, 2014
@ivanlanin
Copy link
Contributor

Yay. I'm really glad we found the solution. I agree with you. We should put this in the docs. Thanks and enjoy your new PHPWord 😄

@Progi1984 Progi1984 reopened this Jun 2, 2014
@Progi1984
Copy link
Member

@todo : Close when an information has been added to docs :)

@ivanlanin
Copy link
Contributor

Information added: e3dd449

@Progi1984
Copy link
Member

An idea for correcting this issue : add an exception if the sys_get_temp_dir is not writable / readable ( http:https://www.php.net/manual/fr/function.is-writeable.php - http:https://www.php.net/manual/fr/function.is-readable.php )

@ivanlanin
Copy link
Contributor

Or, there's a setting that allows user to change the temporary folder. I've put is_writable(sys_get_temp_dir()) as a part of requirement checking in samples/index.php. I think it will be sufficient for now.

@Progi1984
Copy link
Member

@ivanlanin Yes, you're right. I close it. Good job.

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

No branches or pull requests

3 participants