致命错误:带有消息的未捕获异常'com_exception'。同时将ppt转换为jpg

时间:2012-05-21 12:50:44

标签: php powerpoint jpeg

当我运行吹码时:

/*** 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; 

它给了我一个例外:

  

致命错误:未捕获的异常'com_exception',消息'来源: Microsoft Office PowerPoint 2007 说明: PowerPoint无法打开该文件。 “在E:\ wamp \ www \ temp \ video_conversion.php:107堆栈跟踪:#0 E:\ wamp \ www \ temp \ video_conversion.php(107):variant-> Open('E:\ wamp \ www \ tem ...')在第107行的E:\ wamp \ www \ temp \ video_conversion.php中抛出#1 {main}

我无法弄清问题是什么。

3 个答案:

答案 0 :(得分:4)

这是一个问题是由于以下因素。

  1. PHP.ini设置
  2. 文件夹权限
  3. 允许在服务器中启用“
  4. 允许上传尺寸

答案 1 :(得分:3)

在您的错误中,您会看到以下消息:PowerPoint could not open the file.' in E:\wamp\www\temp\video_conversion.php:107

PHP用户是否拥有文件E:\wamp\www\temp/a.pptx的权限?

尝试更正斜杠:E:\wamp\www\temp\a.pptx因为/通常是指选项或参数。

在一天结束时,它似乎是权限错误,位置问题或类似问题,导致无法访问该文件。您可以使用fopenfile_get_contents打开文件吗?

答案 2 :(得分:2)

尝试使用com类:

COM类参考: - 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>

或试试这个:

$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();