【问题标题】:Using the PhpPowerpoint API as a powerpoint reader使用 PhpPowerpoint API 作为 powerpoint 阅读器
【发布时间】:2017-06-12 19:25:05
【问题描述】:

我正在尝试使用 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();       
?>

出现的错误是:

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

有什么建议吗?

【问题讨论】:

  • 你确定IOFactory 可以从URI 中load() 吗?
  • 既然你这么说,也许不会

标签: php phppowerpoint


【解决方案1】:

您无法从阅读器 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(); 

【讨论】:

  • 这是否意味着我必须将我的 pptx 转换为 zip?怎么把url里的文件复制到本地?
  • PPTX 是一个已更改扩展名的 ZIP 文件。为了将文件复制到本地,我使用管理一些流协议(如 http)的副本
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 2018-05-27
  • 1970-01-01
  • 2019-10-21
  • 2020-02-21
相关资源
最近更新 更多