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

Intermittent Error "PowerPoint found a problem with content in the file"... #132

Open
RightHandedMonkey opened this issue Aug 20, 2015 · 10 comments

Comments

@RightHandedMonkey
Copy link

RightHandedMonkey commented Aug 20, 2015

Intermittently, on creation of a .pptx using the PHPPowerPoint library, I will get an error '"PowerPoint found a problem with content in the file' with the filename and a note:
PowerPoint can attempt to repair the file. If you trust the source of this file, click Repair.

When I open the pptx contents in these files that request repair, I've found that the ppt/media folder is missing one of the image files. The slides are getting the same image file, so I'm not sure what is going on there. I'm starting to think it has something to do with the ZipArchive ( $objZip->addFromString(...) ) call that is silently failing, but I'm not sure. There are no errors in the PHP error log and the problem is infrequent. I can simply rerun the creation another time and it works fine.

Please contact me if you want to see the resulting corrupted pptx file or for other information.

@Progi1984
Copy link
Member

Which version do you use ?

@RightHandedMonkey
Copy link
Author

I think it is version 0.2.0 master. I only have the source code in my project, so I'm not 100% sure.

@Progi1984
Copy link
Member

PHPPowerPoint is actually in version 0.4. And this issue has been fixed in 0.3.

Source : https://github.com/PHPOffice/PHPPowerPoint/blob/403cffa7effccadef1cdf6e4dafb4dab9dc09d6a/CHANGELOG.md#030---2014-09-22

@Progi1984
Copy link
Member

@RightHandedMonkey Could you test with the latest version of the develop branch (with #89 & PR #167) ?

@Progi1984
Copy link
Member

@RightHandedMonkey PHPPowerPoint 0.6.0 has been released. I would like to solve your issue for 0.7.0. Could you test with the latest version of develop branch ?

@Progi1984 Progi1984 added this to the Waiting For Answer milestone Jan 24, 2016
@Progi1984
Copy link
Member

Answer from @RightHandedMonkey :

Thanks for sticking with this and I will test it as soon as I can. The program is great and I use it a lot - so I really need to solve this issue. In trying to track down a solution to the intermittent issue I am having, I've collected an xdebug callgrind profiler dump of both having the issue and when not having the issue when generating the same powerpoint. If you would like a copy of that I can send you a link.

I also added a piece of code to cache files (images) in memory. Since I am inserting the same image on every page I thought the multiple disk accesses could be causing the issue. It reduced my problem somewhat, but did not entirely go away. You might find this code useful as it greatly helps performance when using a lot of image files.

Writer/PowerPoint2007.php

use PhpOffice\PhpPresentation\Writer\PptxImageLoader;
...
//(Around line 300)
//Replaced getting the image directly and instead fed through a loader using cache if file exists
//$imageContents = file_get_contents($imagePath);
$imageContents = PptxImageLoader::loadFileData($imagePath); 

Writer/PptxImageLoader.php

<?php

namespace PhpOffice\PhpPresentation\Writer;

/**
 * Added by SEB to cache files that are loaded from disk multiple times.
 * Greatly reduces disk access to create the pptx
 * 
 * Usage:
 *    $data = PptxImageLoader::loadFileData($filename);
 * 
 */
class PptxImageLoader {
    static $images = array();
    public static $use_cache = true;

    /**
     * Retrieves and caches file data so that multiple requests for the same file are not necessary
     * @param type $str
     */
    public static function loadFileData($filepath) {
        if (self::$use_cache && array_key_exists($filepath, self::$images)) {
            return self::$images[$filepath];
        } else {
            //load and return string
            self::$images[$filepath] = file_get_contents($filepath);
            return self::$images[$filepath];
        }
    }
}

@Progi1984 Progi1984 modified the milestones: 0.7.0, Waiting For Answer Mar 11, 2016
@Progi1984
Copy link
Member

@RightHandedMonkey May be you can test with develop branch ?

@Progi1984 Progi1984 modified the milestones: Waiting For Answer, 0.7.0 Mar 11, 2016
@meriemagg
Copy link

i am having the same issue! the pptx that i am creating contains up to 2000 slides (on each slide there's an image) 50 to 100 images are missing
i am using the latest version of phppresentation 0.7.0

@Progi1984
Copy link
Member

@RightHandedMonkey PhpPresentation 0.8.0 has been released. I would like to solve your issue for 0.9.0. Could you answer to my question ?

@Progi1984
Copy link
Member

@RightHandedMonkey PhpPresentation 0.9.0 has been released. I would like to solve your issue for 0.10.0. Could you answer to my question ?

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

3 participants