'Count number of slides of ppt file in php

I am trying to get the number of slides of a ppt file. I am getting the number of slides sometimes but sometimes it will not give me the count. I don't get what I'm missing.

function PageCount_PPTX($file) {
    $pageCount = 0;

    $zip = new ZipArchive();
    $file='../assets/uploaded_files/'.$file;
    $cvf=$zip->open($file);
    var_dump($cvf);
    if($zip->open($file,ZipArchive::CREATE) === true) {
        if(($index = $zip->locateName('docProps/app.xml')) !== false)  {
            $data = $zip->getFromIndex($index);
            $zip->close();
            $xml = new SimpleXMLElement($data);
            print_r($xml);
            $pageCount = $xml->Slides;
        }
    }
    exit();
    return $pageCount;
}

Can anyone help me sort out this issue?



Solution 1:[1]

If you were to use Aspose.Slides Cloud SDK for PHP, you would get the number of presentation slides as shown below:

use Aspose\Slides\Cloud\Sdk\Api\Configuration;
use Aspose\Slides\Cloud\Sdk\Api\SlidesApi;

$configuration = new Configuration();
$configuration->setAppSid("client_id");
$configuration->setAppKey("client_secret");

$slidesApi = new SlidesApi(null, $configuration);

// Get information about slides from a presentation saved to a storage.
$slidesInfo = $slidesApi->getSlides("example.pptx");

// Get the slide count.
$slideCount = count($slidesInfo->getSlideList());

This REST-based library provides many features for managing presentations. This is a paid product, but you can make 150 API calls per month for evaluating all features and your purposes. I work as a Support Developer at Aspose.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrey Potapov