当我运行吹气代码时:
/*** 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...'( #1 {main} 在第 107
行抛出 E:''wamp''www''temp''video_conversion.php
我无法弄清楚问题出在哪里。
这个问题是由于
以下因素造成的。
- PHP .ini设置
- 文件夹权限
- 服务器中未启用允许打开
- 允许的上传大小
在您的错误中,您会看到以下消息: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
/
通常是指选项或参数。
归根结底,它似乎是权限错误,位置问题或类似问题,阻止访问该文件。你能用fopen
或file_get_contents
打开文件吗?
试试这个 com class:
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();