9

When I run blow code:

/*** PPT to Image conversion ***/
$ppt_file = 'E:\wamp\www\temp/a.pptx';
$app = new COM("PowerPoint.application") or die("Unable to instantiate PowerPoint");
$app->Visible = true;
$app->Presentations->Open($ppt_file); 
$app->Presentations[1]->SaveAs("E:/tmp/outdir",18);
$app->Presentations[1]->Close();
$app->Quit();
$app = null; 

It gives me one exception :

Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107 Stack trace: #0 E:\wamp\www\temp\video_conversion.php(107): variant->Open('E:\wamp\www\tem...') #1 {main} thrown in E:\wamp\www\temp\video_conversion.php on line 107

I am unable to figure out what is the problem.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Ravi Sharma
  • 1,162
  • 3
  • 11
  • 20

3 Answers3

4

This is kind of issue is due to the following factors.

  1. PHP.ini settings
  2. Folder Permission
  3. allow open is not enabled in the server
  4. allowed upload size
Johndave Decano
  • 2,101
  • 2
  • 16
  • 16
3

Within your error, you see the following message: PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107

Does the PHP user have permissions to the file E:\wamp\www\temp/a.pptx?

Try correcting your slashes: E:\wamp\www\temp\a.pptx as / normally refers to an option or argument.

At the end of the day, it appears to be a permissions error, a location issue or alike which is preventing access to that file. Can you open the file with fopen or file_get_contents?

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
2

Try this with com class:

COM class Reference: - http://us2.php.net/manual/en/class.com.php

<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<?
    $ppApp = new COM("PowerPoint.Application");
    $ppApp->Visible = True;

    $strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp

    $ppName = "MySlides.ppt";
    $FileName = "MyPP";

    //*** Open Document ***//
    $ppApp->Presentations->Open(realpath($ppName));

    //*** Save Document ***//
    $ppApp->ActivePresentation->SaveAs($strPath."/".$FileName,17);  //'*** 18=PNG, 19=BMP **'
    //$ppApp->ActivePresentation->SaveAs(realpath($FileName),17);

    $ppApp->Quit;
    $ppApp = null;
?>
PowerPoint Created to Folder <b><?=$FileName?></b>
</body>
</html>

Or try this :

$powerpnt = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint");

$presentation = $powerpnt->Presentations->Open(realpath($file), false, false, false) or die("Unable to open presentation");

foreach($presentation->Slides as $slide)

{

    $slideName = "Slide_" . $slide->SlideNumber;

    $exportFolder = realpath($uploadsFolder);

    $slide->Export($exportFolder."\\".$slideName.".jpg", "jpg", "600", "400");

}

$powerpnt->quit();
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Abid Hussain
  • 7,724
  • 3
  • 35
  • 53