使用PhpPowerpoint API作为powerpoint阅读器

时间:2017-06-12 19:25:06

标签: php phppowerpoint

我正在尝试使用PhpPowerpoint API动态地将powerpoint嵌入到我的网页中,但没有成功。

这是我的代码:

<?php     
    use PhpOffice\PhpPresentation\PhpPresentation;
    use PhpOffice\PhpPresentation\IOFactory;
    use PhpOffice\PhpPresentation\Style\Alignment;
    use PhpOffice\PhpPresentation\Style\Color;
    use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
    use PhpOffice\PhpPresentation\Style\Fill;

    require_once 'PhpPresentation/src/PhpPresentation/Autoloader.php';
    \PhpOffice\PhpPresentation\Autoloader::register();

    require_once 'Common/src/Common/Autoloader.php';
    \PhpOffice\Common\Autoloader::register();

    $pptReader = IOFactory::createReader('PowerPoint2007');
    $oPHPPresentation = $pptReader->load('http://webitcloud.net/PW/1617/weduc/Teste.pptx');

    $oTree = new PhpPptTree($oPHPPresentation);
    echo $oTree->display();       
?>

显示的错误是:

  

&#39;无法打开http://webitcloud.net/PW/1617/weduc/Teste.pptx阅读!文件不存在。&#39;在/home/webitcloud/public_html/PW/1617/weduc/PhpPresentation/src/PhpPresentation/Reader/PowerPoint2007.php:97

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您无法从阅读器PowerPoint2007中打开URI,因为它尝试使用ZipArchive(不接受URI)打开它。

解决方案是在本地复制文件:

$file = 'http://remote/url/file.zip';
$newfile = 'tmp_file.zip';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
$pptReader = IOFactory::createReader('PowerPoint2007');
$oPHPPresentation = $pptReader->load($newfile);

$oTree = new PhpPptTree($oPHPPresentation);
echo $oTree->display();