2012-05-21 92 views
9

當我運行的打擊代碼:致命錯誤:帶消息的未捕獲異常'com_exception'。而轉換的PPT JPG

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

它給了我一個例外:

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

我無法弄清楚是什麼問題。

+0

有你在代碼直接打開排除權限問題? –

+0

您是否找到解決方案?我有個類似的問題。 –

回答

4

這是一個問題是由於以下因素。

  1. php.ini設置
  2. 文件夾權限
  3. 允許開放未在服務器中啓用
  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打開文件嗎?

+0

斜線只是一個錯字。 Lemmy試着用文件獲取內容並告訴你會發生什麼。 –

+0

運行file_get_contents? –

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(); 
相關問題