致命错误:在将ppt转换为jpg时出现'com_exception'异常消息。

9

当我运行以下代码时:

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

这个程序抛出了一个异常:

致命错误:Uncaught exception 'com_exception' with message '源:Microsoft Office PowerPoint 2007
描述:PowerPoint 无法打开文件。' 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

我无法确定问题所在。


你是否通过从代码中直接打开文件来排除了权限问题? - Paul B.
你找到解决办法了吗?我也遇到了类似的问题。 - Shadrack Orina
3个回答

4
这种问题通常由以下因素导致:
  1. PHP.ini设置
  2. 文件夹权限
  3. 服务器未启用allow open
  4. 允许上传大小

请注意,以上内容仅供参考。

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打开该文件?

斜杠只是一个打字错误。让我试试使用file_get_contents并告诉你会发生什么。 - Shadrack Orina
file_get_contents有什么进展了吗? - Mike Mackintosh

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接